djangomongodbdjongo

Can't connect MongoDB with Djongo, Connection timeout error occurs


settings.py

enter image description here

requirements.py

enter image description here

docker-compose.yml

enter image description here

error message.

raise ServerSelectionTimeoutError(
pymongo.errors.ServerSelectionTimeoutError: 
ac-yyvwtll-shard-00-00.gcdfin1.mongodb.net:27017: connection closed,
ac-yyvwtll-shard-00-01.gcdfin1.mongodb.net:27017: connection closed,
ac-yyvwtll-shard-00-02.gcdfin1.mongodb.net:27017: connection closed, 
Timeout: 30s, Topology Description: <TopologyDescription id: 62f603001b491814aad289bb, 
topology_type: ReplicaSetNoPrimary, 
servers: [<ServerDescription ('ac-yyvwtll-shard-00-00.gcdfin1.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('ac-yyvwtll-shard-00-00.gcdfin1.mongodb.net:27017: connection closed')>, 
<ServerDescription ('ac-yyvwtll-shard-00-01.gcdfin1.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('ac-yyvwtll-shard-00-01.gcdfin1.mongodb.net:27017: connection closed')>, 
<ServerDescription ('ac-yyvwtll-shard-00-02.gcdfin1.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('ac-yyvwtll-shard-00-02.gcdfin1.mongodb.net:27017: connection closed')>]>


Solution

  • I have fixed this error by downgrading pymongo version to 3.12.3 and adding the IP address (allow access from anywhere) in network access on the MongoDB cluster.