updateOne()
Reference group: Collection CRUD methods
What it does
Updates at most one matching document; update operators target fields.
Syntax
db.collection.updateOne(filter, update, options)
Use case
Apply atomic field changes or counters.
updateOne(): practical example
db.inventory.updateOne({ sku: "KB-1" }, { $inc: { stock: -1 } })💡 Explanation
Updates at most one matching document; update operators target fields.
When to use it
Apply atomic field changes or counters.
Key Takeaways
- Updates at most one matching document; update operators target fields.
- Typical use: Apply atomic field changes or counters.