Important
Inserting documents is not permitted in MongoDB Compass Readonly Edition.
Compass provides the following view modes to insert documents into your collections:
- Shell Syntax Mode
- Write or paste documents in the MongoDB shell syntax, which allows unquoted field names and type constructors such as
ObjectId()andISODate(). Use this mode to insert multiple documents at once as an array. - Field-by-Field Editor
- Select individual field values and types for each inserted document. This mode only supports inserting one document at a time.
- JSON Mode
- Write or paste documents in Extended JSON format, which requires quoted field names and represents BSON types as wrappers such as
{"$oid": "..."}. Use this mode to insert multiple documents at once as an array.
Procedure
To insert documents into your collection, select the tab corresponding to your chosen view mode:
Insert your documents.
In the MongoDB shell syntax, type or paste the document(s) you want to insert into the collection. To insert multiple documents, enter a comma-separated array of documents.
Example
The following example inserts a single document into the collection. Field names are unquoted, and the _id, copies, and lastCheckedOut values use the ObjectId(), NumberInt(), and ISODate() type constructors instead of Extended JSON type wrappers:
{ _id: ObjectId('507f1f77bcf86cd799439011'), title: 'The Odyssey', author: 'Homer', copies: NumberInt('10'), lastCheckedOut: ISODate('2025-03-14T09:30:00Z') }
Note
If you do not specify an _id value in your document, Compass automatically generates an ObjectId for the _id field.
Add new fields.
To add a new field in the document, hover over the row number in the dialog and click the icon to add a new field after the selected row.
You can also add a new field at the end of the document by pressing the tab key when your text cursor is in the value of the last document field.
Note
If you do not specify an _id value in your document, Compass automatically generates an ObjectId for the _id field.
Insert your documents.
In JSON format, type or paste the document(s) you want to insert into the collection. To insert multiple documents, enter a comma-separated array of JSON documents.
Example
The following array inserts 5 documents into the collection:
[ { "_id" : 8752, "title" : "Divine Comedy", "author" : "Dante", "copies" : 1 }, { "_id" : 7000, "title" : "The Odyssey", "author" : "Homer", "copies" : 10 }, { "_id" : 7020, "title" : "Iliad", "author" : "Homer", "copies" : 10 }, { "_id" : 8645, "title" : "Eclogues", "author" : "Dante", "copies" : 2 }, { "_id" : 8751, "title" : "The Banquet", "author" : "Dante", "copies" : 2 } ]
Note
If you do not specify an _id value in your document, Compass automatically generates an ObjectId for the _id field.