Complete the code to update a single field atomically in a MongoDB document.
db.collection.updateOne({ _id: 1 }, { [1]: { score: 100 } })The $set operator updates the value of a field atomically in a single document.
Complete the code to increment a numeric field atomically in a MongoDB document.
db.collection.updateOne({ _id: 2 }, { [1]: { visits: 1 } })The $inc operator increments a numeric field atomically by the specified value.
Fix the error in the update command to atomically add a value to an array field without duplicates.
db.collection.updateOne({ _id: 3 }, { [1]: { tags: "mongodb" } })The $addToSet operator adds a value to an array only if it does not already exist, ensuring atomicity.
Fill both blanks to atomically update multiple fields in a single document.
db.collection.updateOne({ _id: 4 }, { [1]: { score: 90, level: 5 } })Using $set for both fields updates them atomically in a single document.
Fill all three blanks to atomically update a document: increment visits, add a tag uniquely, and set status.
db.collection.updateOne({ _id: 5 }, { [1]: { visits: 1 }, [2]: { tags: "new" }, [3]: { status: "active" } })Use $inc to increment visits, $addToSet to add unique tags, and $set to update status atomically.