0
0
MongoDBquery~5 mins

$min and $max update operators in MongoDB - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the $min update operator do in MongoDB?
The $min operator updates the value of a field only if the specified value is less than the current value in the document.
Click to reveal answer
beginner
How does the $max update operator work in MongoDB?
The $max operator updates the value of a field only if the specified value is greater than the current value in the document.
Click to reveal answer
beginner
If a document field has the value 10, what happens when you use $min: 15 to update it?
Nothing changes because 15 is not less than the current value 10. $min only updates if the new value is smaller.
Click to reveal answer
beginner
If a document field has the value 20, what happens when you use $max: 15 to update it?
Nothing changes because 15 is not greater than the current value 20. $max only updates if the new value is larger.
Click to reveal answer
intermediate
Can $min and $max operators be used together in a single update?
Yes, you can use both $min and $max in the same update to conditionally update different fields based on their values.
Click to reveal answer
What will { $min: { score: 50 } } do if the current score is 40?
AUpdate score to 50
BKeep score as 40
CRemove the score field
DSet score to null
Which operator updates a field only if the new value is greater than the current value?
A$min
B$inc
C$set
D$max
If you want to ensure a field never goes below 10, which operator would you use?
A$min with value 10
B$set with value 10
C$max with value 10
D$inc with value 10
Can $min operator increase the value of a field?
ANo, only decreases or keeps the value
BYes, always
CYes, but only for strings
DNo, it removes the field
What happens if the field does not exist and you use $max: 5 in an update?
AThe field is created with value 5
BThe update fails
CThe field remains missing
DThe field is created with value null
Explain how the $min and $max update operators work in MongoDB with an example.
Think about when the field value changes or stays the same.
You got /3 concepts.
    Describe a real-life scenario where using $min or $max operators would be helpful.
    Consider tracking scores, prices, or limits.
    You got /3 concepts.