1. Update one
updateOne modifies the first document matching the filter.
db.users.updateOne(Typorithm · medium
Step 1 of 8 · intro card
CRUD
updateOne edits the first match; updateMany edits all matches. Use $set to change specific fields without replacing the whole document; add upsert: true to insert when nothing matches.
Updates take a filter plus an update document. updateOne touches the first match; updateMany touches every match.
Always use update operators like $set: { $set: { age: 37 } } changes only the age field, leaving everything else untouched.
Passing a plain object without operators would replace the whole document; add { upsert: true } as a third argument to insert a new document when the filter matches nothing.
updateOne edits the first match.
updateMany edits all matches.
$set changes fields without replacing the doc.
db.users.updateOne(
{ name: "Ada" },
{ $set: { age: 37 } },
)
db.users.updateMany({ active: false }, { $set: { active: true } })Connect each part of the code to the concept before you type.
updateOne modifies the first document matching the filter.
db.users.updateOne($set changes only the named fields, leaving the rest of the document intact.
{ $set: { age: 37 } }updateMany applies the update to every matching document.
db.users.updateMany({ active: false }, { $set: { active: true } })The first argument is the filter selecting which documents to update.
{ active: false }Read the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.