Try Studio 3T for Free
  1. Knowledge Base
  2. MongoDB Tutorials
  3. How to Update MongoDB Documents

How to Update MongoDB Documents

There are various methods for updating documents in a collection, whether it’s for one document, multiple, or all documents.

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.

Download the latest Studio 3T version to follow along the tutorial.


We’ll be using and updating the customers collection in our examples. Here’s the JSON file here which you can import to your MongoDB database following these steps.

Update a single MongoDB document

db.collection.updateOne() updates a single document that matches the specified query criteria.


There is a customer named Phylis Grey in our customers collection. Her last name was misspelled and needs to be corrected to Gray.

Update via mongo shell or IntelliShell

In the mongo shell or on IntelliShell, we would run the following updateOne() command:

   { "_id" : ObjectId("57d28452ed5d4d54e8687078") },
   { $set: { "last" : "Gray" }

If successful, you will see matchedCount = 1 and modifiedCount = 1:

MongoDB update: single documents in the mongo shell

Update via Tree View and Table View

You can do the same update in Tree View and Table View using In-Place Data Editing. All you need to do is double-click on any cell to edit its value.

  1. Build a query through the Visual Query Builder.
  2. Run the query.
  3. Locate the target document – in this case, our customer Phylis Grey – and double-click on the target field last to edit its value.MongoDB update via In-Place Editing
  4. Type the new value and press Enter.

Update via JSON View

  1. Right-click on the target document.
  2. Choose Edit document.
  3. Find the target field and type in the new value.MongoDB update document: JSON View

4. Validate the code (if needed) and click Update.

Update multiple MongoDB documents (e.g. matching the query criteria)

db.collection.updateMany() updates all documents within a collection that match the query criteria.


The XXL package has been discontinued, so all 197 customers with this package need to be moved to the Premium package.

197 customers whose package need to be updated

Update via mongo shell or IntelliShell

We can perform the bulk update by running the updateMany() command:

    { "package" : "XXL" }, 
    { $set: { "package" : "Premium" } 

In one go, the query successfully updated matched and modified 197 documents.

MongoDB update: 197 documents were matched and modified

Update via Tree View and Table View

  1. Build the query to get to the 197 customers through the Visual Query Builder (drag the field package into the builder and type XXL as value), or type the query { "package": "XXL" }  in the Main Query Bar.
  2. Run the query.
  3. Right-click on the target field, which in this case is package.
  4. Choose Field > Edit Value/Type.
  5. Update the value from XXL to Premium.
  6. Choose to set the fields in either “Documents matching query criteria”, “Documents matching query criteria that have this field”, “All documents in collection”, or “All Documents in collection that have this field”.In this example, we will choose “Documents matching query criteria“.

    Update MongoDB documents matching query criteria

  7. Click Set Value.

To update all documents in a MongoDB collection, you would instead need to choose All documents in collection.

Complement this short read with another on how MongoDB insert() works in Studio 3T, or how to rename MongoDB fields without typing a single $rename operator.

Updated on December 5, 2019

Was this article helpful?

Related Articles

Leave a Comment