Navigation

Modify Documents

Important

Modifying documents is not permitted in MongoDB Compass Readonly Edition.

You can edit existing documents in your collection. When you edit a document, Compass performs a findAndModify operation to update the document.

Select the appropriate tab based on whether you are viewing your documents in List, JSON, or Table view:

Document View Selection

To modify a document, hover over the document and click the pencil icon:

../../_images/edit-doc.png

After you click the pencil icon, the document enters edit mode:

../../_images/edit-doc2.png

You can now make changes to the fields, values, or data types of values.

Delete Fields

To delete a field from a document, click the x icon to the left of the field:

../../_images/edit-doc3.png

Once selected, the field is marked for removal and appears highlighted in red:

../../_images/edit-doc4.png

Add New Fields

To add a new field in the document, hover over the row number in the dialog (the row number is not part of the document but the dialog display) and click on the plus sign add a new field after the field.

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.

Modify an Existing Field

You can modify documents by clicking on existing field names or values and making changes. In this example, the flight status was changed from L to M. Changed fields appear highlighted in yellow:

../../_images/update-field.png

Save Changes

When you are finished editing the document, click the Update button to commit your changes.

Revert a Change

To revert changes to a document, hover over the edited field and click the revert icon which appears to the left of the field’s line number.

../../_images/revert-doc-list-view.png

Note

JSON View is available starting in Compass 1.20.

To modify a document, hover over the document and click the pencil icon:

../../_images/document-edit-json.png

After you click the pencil icon, the document enters edit mode. You can now add, remove, and edit field values by modifying the JSON document.

By default, embedded objects and arrays are hidden. To expand embedded objects and array elements, hover over the target document and click the top arrow on the left side of the document.

To expand individual objects and arrays, click the arrow to the left of the desired field.

Expand embedded objects JSON

To modify a document, hover over the document and click the pencil icon:

../../_images/table-view-modify.png

After you click the pencil icon, the document enters edit mode:

../../_images/document-edit-table.png

Delete Fields

To delete a field from a document:

  1. Click the value of the field you want to delete.
  2. Click the trash icon icon.
  3. Click Update to confirm your changes.

Add New Fields

To add a new field to the document:

  1. Click the field after which you wish to add the new field.
  2. Click the plus square icon icon.
  3. Click Add Field after <Field Name>.
  4. Populate your newly created field.
  5. Click Update to confirm your changes.

Revert a Change

While modifying a document, you have the option to revert changes made to a field prior to saving the modified document.

Click the revert icon which appears on the right side of the edited table element.

../../_images/revert-doc-table-view.png

Cancel Changes

To exit the edit mode and cancel all pending changes to the document, click the Cancel button.