Update Multiple Documents
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.
Example
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