LOGBOOK

HELP

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 $set specifying new values
  • updateMany updates ALL matching documents
  • Use updateOne to update only the first match

From Quiz: WEBT / Database Connections | Updated: Jun 20, 2026