For AI agents: a documentation index is available at https://www.mongodb.com/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.
Docs Menu

Insert Documents

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() and ISODate(). 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.

To insert documents into your collection, select the tab corresponding to your chosen view mode:

1

In the drop-down menu, click Insert Document.

Insert button
click to enlarge

Alternatively, you can right-click the query bar or its surrounding whitespace and select Insert document... from the drop-down menu.

2

In the Insert Document modal, click the icon to use Shell Syntax mode to insert documents into your collection.

Shell Syntax mode is the default view.

3

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.

4
Rate this page

On this page