thinkarlabs / P23-002-HealthKiosk

MIT License
0 stars 0 forks source link

Learning of Python basics with MongoDB #18

Closed mjunedi closed 1 year ago

basumadiwalar commented 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" }

information.insert_one(records5)

Now able to insert data via Python

basumadiwalar commented 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)

mjunedi commented 1 year ago

Learning completed with sample code