Changing existing data uses updateOne() or updateMany(), paired with update operators that describe exactly what should change.
db.users.updateOne(
{ name: "Karan Mehta" },
{ $set: { age: 23 } }
)$inc adds (or, with a negative number, subtracts) a value to a numeric field — useful for counters, without needing to read the current value first:
db.products.updateOne(
{ name: "Notebook" },
{ $inc: { stock: -1 } }
)db.users.updateOne(
{ name: "Karan Mehta" },
{ $push: { skills: "TypeScript" } }
)db.users.updateOne(
{ name: "Karan Mehta" },
{ $unset: { temporaryFlag: "" } }
)db.users.updateMany(
{ isActive: false },
{ $set: { status: "archived" } }
)A missing operator replaces the whole document
Forgetting the update operator and writing { age: 23 } instead of { $set: { age: 23 } } replaces the entire document with just { age: 23 }, deleting every other field. Always wrap changes in an operator like $set.