> For the complete MongoDB documentation index, see www.mongodb.com/docs/llms.txt

<!--
Tab options on this page. Append to the .md URL to filter:
  ?tabs=<id,...>   select specific tabs (e.g. ?tabs=nodejs,shell)
  ?allTabs=true    include every tab
  (no param)       default: one tab per tabset

Available tabs:
  other tabs: list-view, json, table-view
-->

# Modify Single Document

MongoDB Compass Readonly Edition will be deprecated in a future release. To replicate the read-only behavior in a standard Compass edition, assign users [`read`](https://www.mongodb.com/docs/manual/reference/built-in-roles.md#mongodb-authrole-read) access at the database level and enable the [readOnly](https://www.mongodb.com/docs/compass/settings/read-only.md#std-label-compass-read-only) option in Compass.

You can edit existing documents in your collection.

When you edit a document in List or Table view, Compass performs a [findOneAndUpdate](https://www.mongodb.com/docs/manual/reference/method/db.collection.findOneAndUpdate/) operation and updates only those fields that you have changed.

When you edit a document in JSON view, Compass performs a [findOneAndReplace](https://www.mongodb.com/docs/manual/reference/method/db.collection.findOneAndReplace/) operation and replaces the document.

## Limitations

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

## Procedure

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

![Document View Selection](/images/compass/documents-view-select.svg)

### List View

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

![Document Edit Selection](/images/compass/edit-doc.svg)

Alternatively, you can right-click on the document and select Edit document from the drop-down menu.

After you click the pencil icon or select Edit document, the document enters edit mode. 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  icon to the left of the field:

![Document Deletion](/images/compass/edit-doc3.svg)

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.

### Add New Fields

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](/images/compass/add-field.svg)

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

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](/images/compass/update-field.png)

When you edit a document in List or Table view, Compass performs a [findOneAndUpdate](https://www.mongodb.com/docs/manual/reference/method/db.collection.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 Replace, or cancel your changes.

### 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.

![Revert Document in List View](/images/compass/revert-doc-list-view.svg)

## Cancel Changes

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

## Modify Multiple Documents

You can use the bulk update operations workflow to update multiple documents in Compass. For details, see [Modify Multiple Documents.](https://www.mongodb.com/docs/compass/documents/modify-multiple.md#std-label-compass-bulk-update)

**Note:**

You can also use the [db.collection.updateMany()](https://www.mongodb.com/docs/manual/reference/method/db.collection.updateMany/) method in the [embedded MongoDB Shell](https://www.mongodb.com/docs/compass/embedded-shell.md#std-label-embedded-mongodb-shell) to update multiple documents in a single operation.
