In MongoDB, a Create operation consists of inserting documents into a collection. This page provides examples.
You can insert documents in MongoDB by using the following methods:
Your programming language's driver.
The MongoDB Atlas UI. To learn more, see Delete a Document with Atlas.
Note
Creating a Collection
Inserting a document into a collection that doesn't exist creates that collection.
Insert Behavior
Collection Creation
If the collection does not currently exist, insert operations create the collection.
_id Field
In MongoDB, each document stored in a standard collection requires a unique _id field that acts as a primary key. If an inserted document omits the _id field, the MongoDB driver automatically generates an ObjectId for the _id field.
This also applies to documents inserted through update operations with upsert: true.
Note
Atomicity and Write Acknowledgement
MongoDB write operations are atomic on the level of a single document. For more information, see Atomicity and Transactions.
You can also use write concerns to specify the level of acknowledgment requested from MongoDB for write operations. For more information, see Write Concern.