Insert in MongoDB

 Refer :Insert Documents — MongoDB Shell

Insert Documents

The MongoDB shell provides the following methods to insert documents into a collection:

db.collection.insertOne() inserts a single document into a collection. If the document does not specify an _id field, MongoDB adds the _id field with an ObjectId value to the new document.


insertOne() returns a document that includes the newly inserted document's _id field value.

db.movies.find( { title: "The Favourite" } )

db.collection.insertMany() can insert multiple documents into a collection. Pass an array of documents to the method. If the documents do not specify an _id field, MongoDB adds the _id field with an ObjectId value to each document. 


insertMany() returns a document that includes the newly inserted documents' _id field values.

To read documents in the collection:

db.movies.find( {} )

db.collectionName.find().pretty() [will show in formatted]

Post a Comment

Please Select Embedded Mode To Show The Comment System.*

Previous Post Next Post

Contact Form