I am having trouble connecting to the mongoDB atlas servers when connecting to the database.
from pymongo.mongo_client import MongoClient
from pymongo.server_api import ServerApi
uri = “mongodb+srv://KaraboM:@bigdata.maa2f.mongodb.net/?retryWrites=true&w=majority&appName=BigData”
Create a new client and connect to the server
client = MongoClient(uri, server_api=ServerApi(‘1’))
Send a ping to confirm a successful connection
try:
client.admin.command(‘ping’)
print(“Pinged your deployment. You successfully connected to MongoDB!”)
except Exception as e:
print(e)
Output should be:
Pinged your deployment. You successfully connected to MongoDB!
Error:
bigdata-shard-00-01.maa2f.mongodb.net:27017: timed out (configured timeouts: socketTimeoutMS: 20000.0ms, connectTimeoutMS: 20000.0ms),bigdata-shard-00-02.maa2f.mongodb.net:27017: timed out (configured timeouts: socketTimeoutMS: 20000.0ms, connectTimeoutMS: 20000.0ms),bigdata-shard-00-00.maa2f.mongodb.net:27017: timed out (configured timeouts: socketTimeoutMS: 20000.0ms, connectTimeoutMS: 20000.0ms), Timeout: 30s, Topology Description: <TopologyDescription id: 66ef302b30237da477ea951b, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription (‘bigdata-shard-00-00.maa2f.mongodb.net’, 27017) server_type: Unknown, rtt: None, error=NetworkTimeout(‘bigdata-shard-00-00.maa2f.mongodb.net:27017: timed out (configured timeouts: socketTimeoutMS: 20000.0ms, connectTimeoutMS: 20000.0ms)’)>, <ServerDescription (‘bigdata-shard-00-01.maa2f.mongodb.net’, 27017) server_type: Unknown, rtt: None, error=NetworkTimeout(‘bigdata-shard-00-01.maa2f.mongodb.net:27017: timed out (configured timeouts: socketTimeoutMS: 20000.0ms, connectTimeoutMS: 20000.0ms)’)>, <ServerDescription (‘bigdata-shard-00-02.maa2f.mongodb.net’, 27017) server_type: Unknown, rtt: None, error=NetworkTimeout(‘bigdata-shard-00-02.maa2f.mongodb.net:27017: timed out (configured timeouts: socketTimeoutMS: 20000.0ms, connectTimeoutMS: 20000.0ms)’)>]>
Karabo Mokgotloa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.