Connecting to atlas

Having an issue connecting to Altas Cluster, I have whitelisted ip To ensure I was able to connect to the db I printed the collection name to console. But when I try and insert a document into the collection, I get this error.

pymongo.errors.ServerSelectionTimeoutError: : [Errno 8] nodename nor servname provided, or not known

I have tried
collection_name.insert_one(json_data) same error.

from pymongo import MongoClient

conn = MongoClient()
print(“Connected successfully!!!”)
print(“Could not connect to MongoDB”)


db = conn.my_database

Created or Switched to collection names

collection = db.my_collection

emp_rec1 = {
emp_rec2 = {

Insert Data

rec_id1 = collection.insert_one(emp_rec1)
rec_id2 = collection.insert_one(emp_rec2)

Please keep you question in one thread. The discussion has started in Connect to Atlas with Pymongo and you should close this thread.

1 Like