from pymongo import MongoClient
mongo_url = "mongodb://localhost:27017"
mongo_db = MongoClient(mongo_url)
#print(mongo_db.list_database_names())
#Create db
db = mongo_db["TestDB5"]
#Create collection
col1 = db.get_collection("TestColl5")
#Create document
data = dict()
data["Name"] = "John"
data["Age"] = 17
data["Id"] = 7
data["Class"] = 8
data["FinalScore"] = 76
x= col1.insert_one(data).inserted_id
print("Data created successfully")
Rather:
col1 = db.create_collection("TestColl5")
@Sathyan_R if you’re still facing this error please post the entire Python traceback so we can see which line(s) the error gets raised on.