Docs Menu
Docs Home
/
MongoDB Compass
/ /

Modify Single Document

On this page

  • Limitations
  • Procedure
  • Cancel Changes
  • Modify Multiple Documents

You can edit existing documents in your collection.

When you edit a document in List or Table view, Compass performs a findOneAndUpdate operation and updates only those fields that you have changed.

When you edit a document in JSON view, Compass performs a findOneAndReplace operation and replaces the document.

  • Modifying documents is not permitted in MongoDB Compass Readonly Edition.

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

Document View Selection
click to enlarge

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

Document Edit Selection
click to enlarge

After you click the pencil icon, the document enters edit mode. You can now make changes to the fields, values, or data types of values.

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

Document Deletion
click to enlarge

Once selected, the field is marked for removal and appears highlighted in red. Compass asks for confirmation that you want to update the document by removing the field.

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

Add a field to a document
click to enlarge

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.

To modify documents, click on existing field names or values and make changes. In this example, the borough was changed from Manhattan to Queens. Changed fields appear highlighted in yellow:

Document Update View
click to enlarge

When you edit a document in List or Table view, Compass performs a findOneAndUpdate operation and updates only those fields that you have changed.

If Compass detects that you have changed fields that were modified outside of Compass, it notifies you, preventing you from accidentally overwriting the changes made outside of Compass. You can choose to proceed and replace the document by clicking Update, or cancel your changes.

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

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.

Revert Document in List View

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

Document Edit Selection in JSON View
click to enlarge

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, this view hides embedded objects and arrays. 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 in JSON view
click to enlarge

When you edit a document in JSON view, Compass performs a findOneAndReplace operation and replaces the document.

If Compass detects that you have changed fields that were modified outside of Compass, it notifies you, preventing you from accidentally overwriting the changes made outside of Compass. You can choose to proceed and replace the document by clicking Update, or cancel your changes.

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

Document Edit Selection in Table View
click to enlarge

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

When you edit a document in List or Table view, Compass performs a findOneAndUpdate operation and updates only those fields that you have changed.

If Compass detects that you have changed fields that were modified outside of Compass, it notifies you, preventing you from accidentally overwriting the changes made outside of Compass. You can choose to proceed and replace the document by clicking Update, or cancel your changes.

To delete a field from a document:

  1. Click the value of the field you want to delete.

  2. Click the icon.

  3. Click Update to confirm your changes.

To add a new field to the document:

  1. Click the field after which you wish to add the new field.

  2. Click the icon.

  3. Click Add Field after <Field Name>.

  4. Populate your newly created field.

  5. Click Update to confirm your changes.

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.

Document Revert Changes in Table View

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

You can use the bulk update operations workflow to update multiple documents in Compass. For details, see Modify Multiple Documents.

Note

You can also use the db.collection.updateMany() method in the embedded MongoDB Shell to update multiple documents in a single operation.

Back

Insert