Search⌘ K
AI Features

Solution: Update a Record

We'll cover the following...
Query
db.orders.updateMany(
{ status: "Cancelled" },
{ $set: { status: "Closed" } }
)
, db.orders.find()

The explanation of the query is given below:

  • Line 1: db.orders.updateMany(, this command tells MongoDB to update multiple documents in the orders collection that match the filter you provide. Use updateMany when you want to change more than one document.

  • Line 2: It selects all documents where the status field equals ...