{ "_id": 1, "score": 50 } and the update operation { "$min": { "score": 40 } }, what will be the value of score after the update?db.collection.updateOne({ _id: 1 }, { $min: { score: 40 } })
db.collection.findOne({ _id: 1 })The $min operator updates the field only if the new value is less than the current value. Since 40 is less than 50, the score is updated to 40.
{ "_id": 2, "level": 10 } and the update operation { "$max": { "level": 15 } }, what will be the value of level after the update?db.collection.updateOne({ _id: 2 }, { $max: { level: 15 } })
db.collection.findOne({ _id: 2 })The $max operator updates the field only if the new value is greater than the current value. Since 15 is greater than 10, the level is updated to 15.
stats.score to 30 only if 30 is less than the current value. Which of the following update operations is correct?MongoDB uses dot notation to specify nested fields in update operations. Option C correctly uses "stats.score" as the field name.
{ "_id": 3, "points": 100 } and the update { "$max": { "points": 80 } }, what will be the value of points after the update?db.collection.updateOne({ _id: 3 }, { $max: { points: 80 } })
db.collection.findOne({ _id: 3 })The $max operator updates the field only if the new value is greater than the current value. Since 80 is less than 100, the field remains unchanged.
The $min and $max operators allow atomic updates to a field only if the new value is less or greater respectively. This avoids race conditions and the need to read the document before updating.