MongoDB — Updating Documents & Field Modifiers

🍃 MongoDB 7.0+ 🟢 Chapter 20 of 50 📂 Phase 04: Advanced Querying, Array & Embedded Documents 📅 2026 Edition

Modify documents atomically using updateOne(), updateMany(), $set, $unset, $inc, and $rename.

1Update Modifiers Cheat Sheet
ModifierDescriptionExample
$setSets/creates field value{ $set: { status: "active" } }
$unsetDeletes field{ $unset: { tempToken: "" } }
$incIncrements number{ $inc: { views: 1 } }
$renameRenames field{ $rename: { fname: "firstName" } }
2updateOne and updateMany Syntax
Update Code Examples
// updateOne: Updates first matching document
db.users.updateOne(
  { _id: ObjectId("65d8f1e2a9b3c4d5e6f7a8b9") },
  { $set: { isVerified: true }, $inc: { loginCount: 1 } }
);

// updateMany: Updates all matching documents
db.users.updateMany(
  { status: "pending" },
  { $set: { status: "expired" } }
);
OC
Written by Our Compiler Technical Editorial Team
Reviewed for accuracy & tested on MongoDB 7.0+ Standards · Last updated August 2026