Python MongoDB

MongoDB Insert

Inserting documents

MongoDB Insert

To insert a record, or document as it is called in MongoDB, into a collection, we use the insert_one() method.

Insert Document

mydict = { "name": "John", "address": "Highway 37" }
x = mycol.insert_one(mydict)
print(x.inserted_id)