replaceOne()
Reference group: Collection CRUD methods
What it does
Replaces the matched document rather than selectively changing fields.
Syntax
db.collection.replaceOne(filter, replacement)
Use case
Replace configuration intentionally.
Important notes
Fields omitted from the replacement are removed.
replaceOne(): practical example
db.settings.replaceOne({ _id: "checkout" }, { _id: "checkout", enabled: true })💡 Explanation
Replaces the matched document rather than selectively changing fields.
When to use it
Replace configuration intentionally.
Caution
Fields omitted from the replacement are removed.
Key Takeaways
- Replaces the matched document rather than selectively changing fields.
- Typical use: Replace configuration intentionally.