Docs Menu

Update Multiple Documents

Note

If you specify a callback method, updateMany() returns nothing. If you do not specify one, this method returns a Promise that resolves to the result object when it completes. See our guide on Promises and Callbacks for more information, or see the API documentation for information on the result object.

You can update multiple documents using the collection.updateMany() method. The updateMany() method accepts a filter document and an update document. If the query matches documents in the collection, the method applies the updates from the update document to fields and values of the matching documents. The update document requires an update operator to modify a field in a document.

You can specify additional options in the options object passed in the third parameter of the updateMany() method. For more detailed information, see the updateMany() API documentation.

Note

You can use this example to connect to an instance of MongoDB and interact with a database that contains sample data. To learn more about connecting to your MongoDB instance and loading a sample dataset, see the Usage Examples guide.

If you run the preceding example, you should see the following output:

Updated 477 documents
Give Feedback
MongoDB logo
© 2021 MongoDB, Inc.

About

  • Careers
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2021 MongoDB, Inc.