The create operation

The create operation inserts the new document into the collection. If a collection does not exist, MongoDB will create a new collection and insert a document in it. MongoDB provides the following methods to insert a document into the database:

  • db.collection.insertOne();
  • db.collection.insertMany();

The MongoDB insert operation will target single collections. Also, mongo preserves atomicity at the document level:

This method returns a document that contains the newly added documents _id value:

The method insertMany(), can ...

Get Seven NoSQL Databases in a Week now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.