Field Update Operators in MongoDB

From the MongoDB cheat sheet · Update Operators · verified Jul 2026

Field Update Operators

Modify document field values

javascript
// Set field values
db.users.updateOne(
  { _id: userId },
  { 
    $set: { name: "John", "address.city": "NYC" },
    $unset: { tempField: "" }
  }
)

// Increment/Decrement
db.products.updateOne(
  { _id: productId },
  { 
    $inc: { 
      views: 1,
      stock: -5 
    }
  }
)

// Multiply value
db.items.updateOne(
  { _id: itemId },
  { $mul: { price: 1.1 } }  // 10% increase
)
🟢 Essential - Most common update operations
💡 $set creates field if it doesn't exist
📌 Use dot notation for nested fields
⚡ $inc is atomic - safe for concurrent updates
⚠️ $unset removes field entirely
updateoperatorsfields

More MongoDB tasks

Back to the full MongoDB cheat sheet