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 ...