db.users.updateOne(
{ _id: 1 },
{ $set: { status: 'active' }, $inc: { loginCount: 1 } }
);Tip
Common mistake: forgetting the update OPERATOR ($set) — without it, Mongo replaces the ENTIRE document.
GoCareerGo Tutorials
Documents, collections, CRUD, aggregation, Atlas and driver connectivity.
Updates the FIRST document that matches a filter, using update operators like $set.
db.users.updateOne(
{ _id: 1 },
{ $set: { status: 'active' }, $inc: { loginCount: 1 } }
);Common mistake: forgetting the update OPERATOR ($set) — without it, Mongo replaces the ENTIRE document.