I’m encountering the following error when trying to fetch banned users and chats using the Motor library with MongoDB Atlas:
Relevant code snippet
b_users, b_chats = await db.get_banned()
b_chats = [chat['id'] async for chat in chats]
Error Message:
pymongo.errors.ServerSelectionTimeoutError: No replica set members match selector "Primary()", Timeout: 30s, Topology Description: <TopologyDescription id: 65217586b0ced5475d5e4b50, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription ('cluster0-shard-00-00.zaiqq.mongodb.net', 27017) server_type: RSSecondary, rtt: 0.0024830238521099095>, <ServerDescription ('cluster0-shard-00-01.zaiqq.mongodb.net', 27017) server_type: Unknown, rtt: None, error=NetworkTimeout('cluster0-shard-00-01.zaiqq.mongodb.net:27017: The read operation timed out')>, <ServerDescription ('cluster0-shard-00-02.zaiqq.mongodb.net', 27017) server_type: RSSecondary, rtt: 0.0026440465152263643>]>
Traceback snippet
Traceback (most recent call last):
File "/root/tessa/bot.py", line 112, in <module>
app.run()
File "/root/tessa/venv/lib/python3.10/site-packages/pyrogram/methods/utilities/run.py", line 80, in run
run(self.start())
File "/usr/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
return future.result()
File "/root/tessa/bot.py", line 41, in start
b_users, b_chats = await db.get_banned()
File "/root/tessa/database/users_chats_db.py", line 82, in get_banned
b_chats = [chat['id'] async for chat in chats]
File "/root/tessa/database/users_chats_db.py", line 82, in <listcomp>
b_chats = [chat['id'] async for chat in chats]
File "/root/tessa/venv/lib/python3.10/site-packages/motor/core.py", line 1158, in next
if self.alive and (self._buffer_size() or await self._get_more()):
File "/usr/lib/python3.10/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
File "/root/tessa/venv/lib/python3.10/site-packages/pymongo/cursor.py", line 1155, in _refresh
self.__send_message(q)
File "/root/tessa/venv/lib/python3.10/site-packages/pymongo/cursor.py", line 1044, in __send_message
response = client._run_operation(
File "/root/tessa/venv/lib/python3.10/site-packages/pymongo/mongo_client.py", line 1424, in _run_operation
return self._retryable_read(
File "/root/tessa/venv/lib/python3.10/site-packages/pymongo/mongo_client.py", line 1514, in _retryable_read
server = self._select_server(
File "/root/tessa/venv/lib/python3.10/site-packages/pymongo/mongo_client.py", line 1346, in _select_server
server = topology.select_server(server_selector)
File "/root/tessa/venv/lib/python3.10/site-packages/pymongo/topology.py", line 244, in select_server
return random.choice(self.select_servers(selector,
File "/root/tessa/venv/lib/python3.10/site-packages/pymongo/topology.py", line 202, in select_servers
server_descriptions = self._select_servers_loop(
File "/root/tessa/venv/lib/python3.10/site-packages/pymongo/topology.py", line 218, in _select_servers_loop
raise ServerSelectionTimeoutError(
pymongo.errors.ServerSelectionTimeoutError: No replica set members match selector "Primary()", Timeout: 30s, Topology Description: <TopologyDescription id: 65217586b0ced5475d5e4b50, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription ('cluster0-shard-00-00.zaiqq.mongodb.net', 27017) server_type: RSSecondary, rtt: 0.0024830238521099095>, <ServerDescription ('cluster0-shard-00-01.zaiqq.mongodb.net', 27017) server_type: Unknown, rtt: None, error=NetworkTimeout('cluster0-shard-00-01.zaiqq.mongodb.net:27017: The read operation timed out')>, <ServerDescription ('cluster0-shard-00-02.zaiqq.mongodb.net', 27017) server_type: RSSecondary, rtt: 0.0026440465152263643>]>
- I’m using the Motor library to connect to MongoDB Atlas.
- The error occurs when attempting to fetch each document from cursor returned by find()
- Using Atlas free tier
- Already added 0.0.0.0/0 in Network access
Any assistance or insights into resolving this issue would be greatly appreciated.