↻
⏵︎ Run
import pymongo myclient = pymongo.MongoClient("mongodb://localhost:27017/") #use database named "organisation" mydb = myclient["organisation"] #use collection named "developers" mycol = mydb["developers"] #dictionary as a document dict = { "name": "Kiku", "address": "Germany" } #insert a document to the collection x = mycol.insert_one(dict) #id returned by insert_one print("Document inserted with id: ", x.inserted_id) print("\nDocuments in developers collection\n----------------------------------") #print all the documents in the collection for x in mycol.find(): print(x)
Output