Quiz Entry - updated: 2026.06.20
How do you update documents in MongoDB?
Call updateMany() with a query selecting the documents and an update object using $set to specify the new field values.
await birthdays.updateMany(
{ name: { $eq: 'Anna' } },
{ $set: { day: new Date('1983-03-21') } }
);
- First parameter: query to select documents (same as
find) - Second parameter: update object with
$setspecifying new values updateManyupdates ALL matching documents- Use
updateOneto update only the first match