Closed mjunedi closed 1 year ago
import pymongo client = pymongo.MongoClient('mongodb://localhost:27017/') mydb=client['NewConnection']
try: conn= client.server_info() print (f'Connected to MongoDB {conn.get("version")}') except Exception: print("Unable to connect to the MongoDB server.") for db in client.list_databases(): print(db) information=mydb.information records5=[{ "EMPNAME":"RAghu", "Empno":14, "college":"dwdmuhubli" },{ "CITY":"DHARAWAD", "CAMPUS":"KUD" }]
information.insert_many(records5)
Learning completed with sample code
import pymongo client = pymongo.MongoClient('mongodb://localhost:27017/') mydb=client['NewConnection']
try: conn= client.server_info() print (f'Connected to MongoDB {conn.get("version")}') except Exception: print("Unable to connect to the MongoDB server.") for db in client.list_databases(): print(db) information=mydb.information records5={ "EMPNAME":"RAghu", "Empno":14, "college":"dwdmuhubli" }
information.insert_one(records5)
Now able to insert data via Python