A document is the basic unit of data in MongoDB. It’s comprised of field/value pairs which are written in BSON format.
A field is the name/value pair in a MongoDB document while a value is the specific value of a document’s field/value pair. A group of documents together is known as a collection.
Fields in a MongoDB document can be of any BSON data type. The full list of types can be found here.
The most important thing to remember is that each MongoDB document requires a unique _id
field, which serves as the primary locator key for each document.
If the user doesn’t specify an _id
field when creating a new document, MongoDB automatically creates ObjectId value represented as a string of numbers. This is shown in the examples below:
ObjectId (default)
{ _id: ObjectId("57d28452ed5d4d54e8687098"), first: "Hugh", last: "Manatee", email: "[email protected]", }
The _id
field is immutable, however you can add a new document with an _id
field of any BSON data type other than array.
An example of a custom ID (in this example, string)
{ _id: "Studio3TMascot", first: "Hugh", last: "Manatee", email: "[email protected]", }
The maximum document size is 16 MB, however MongoDB uses GridFS to accommodate larger documents.
In the following examples, we’ll show you how to run document-related CRUD commands through Studio 3T.
Insert MongoDB documents to a collection
Right-click on any cell while viewing a collection in Table, Tree, or JSON View.and choose Insert Document. Alternatively, use the shortcut Ctrl + D (⌘ + D).

This will open the Insert Document > JSON window.
Type the fields to be added in JSON format. There is no need to add an _id field, as mongod
will create this and assign the document a unique ObjectId
value.

Click on Add Document, or Add & Continue if adding more documents. The new document should then appear in the collection’s Result tab.

Update MongoDB documents (updateone, updatemany)
Depending on which view, Studio 3T offers convenient ways to update a single, multiple, or all documents in a collection.
In Studio 3T, the In-Place Data Editing feature takes care of most updates to a single document. Updates to multiple or all documents can be made easily in a few clicks.
Update a single document
With Table and Tree View, all you need to do is double-click on any cell to edit its value.
Locate the target document – in this case, our customer Phylis Grey – and double-click on the target field last
to edit its value.

Type the new value and press Enter.
With JSON View, right-click on the target document and choose Edit document.
Find the target field and type in the new value. Validate the code (if needed) and click Update.

Update multiple documents (e.g. matching the query criteria, all documents)
In the example below, the XXL package has been discontinued, so we’ve built the query (through the Visual Query Builder) that gives us the list of 197 customers who need to be moved to the Premium package.

In Table or Tree View, right-click on the target field, which in this case is package
.
Choose Field > Edit Value/Type. Update the value from XXL
to Premium
.
Choose to set the fields in either:
- Documents matching query criteria
- Documents matching query criteria that have this field
- All documents in collection
- All Documents in collection that have this field
In this example, we will choose Documents matching query criteria.

Click Set Value.
To update all documents in a MongoDB collection, you would instead need to choose All documents in collection.
Delete MongoDB documents
While in Tree, Table, or JSON View, right-click on the document to delete and choose Remove document or press Shift + Fn + Backspace.

Rename MongoDB fields
Every now and then, you may need to rename MongoDB fields.
Whether you need to do it for a single document, or perhaps for multiple documents, this task can be easily accomplished with only a few steps from within Studio 3T.
Rename a field in a single document
The simplest of these tasks is changing a field name in single document. See the steps below:

- Open the document in which the field to be renamed is located.
- Double click on the field name (In this case “dob”).
- You will now have the option to type the new field name into this space.
- Once you press “Enter” the new field name will be saved.
Rename fields within documents matching a query
Should you wish to change all documents matching a particular query then this can also be easily achieved in just a few steps. In this example we are changing the “dob” field in all documents relating to customers with the last name “Miller”. See below:

- Type in your query:
{last:"Miller"}
– and hit “Enter”. - Open one of the documents resulting from the query search.
- Find the field that you would like to rename (“dob”) and right click it.
- Select “Rename Field”.
- Type in the new field name (“date_of_birth”) and hit “Enter”.
- Select “Documents matching query criteria” from the dropdown box.
- Click “Enter”.
- Now every document within this query will have the field name “date_of_birth” in place of “dob”.
Rename fields in all documents within a collection
Finally, to rename a field in all documents within a collection follow the steps below (identical to the steps above apart from no. 4):

- Find the field that you would like to rename (again “dob”) and right click it.
- Select “Rename Field”.
- Type in the new field name (“date_of_birth”) and hit “Enter”.
- Select “All documents in collection” from the dropdown box.
- Click “Rename”.
- Now every document in the entire collection will have the field name “date_of_birth” in place of “dob”.