Back

Error in  Inserting and Updating Data MongoDB Python

Created 3 years ago
56 Views
2 Comments
GokilaE
@GokilaE
GokilaE
@GokilaEProfile is locked. Login

I'm trying to insert a data in MongoDB I have faced in error kindly go through the code and help me to find the bug.

from pymongo import MongoClient 
try: 
    conn = MongoClient() 
    print("Connected successfully!!!") 
except:   
    print("Could not connect to MongoDB")
db = conn.database 
collection = db.my_gfg_collection 

emp_rec1 = { 
        "name":"Mr.Geek", 
        "eid":24, 
        "location":"delhi"
        } 
emp_rec2 = { 
        "name":"Mr.Shaurya", 
        "eid":14, 
        "location":"delhi"
        } 
rec_id1 = collection.insert_one(emp_rec1,emp_rec2) 
print("Data inserted with record ids",rec_id1," ",rec_id2) 
cursor = collection.find() 
for record in cursor: 
    print(record) 

Comments (2)
Please login to comment.