← All tutorials

GoCareerGo Tutorials

MongoDB Tutorial

Documents, collections, CRUD, aggregation, Atlas and driver connectivity.

updateOne()

Updates the FIRST document that matches a filter, using update operators like $set.

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.