0
0
MongoDBquery~10 mins

$min and $max update operators in MongoDB - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to update the field 'score' only if the new value is less than the current value using the $min operator.

MongoDB
db.collection.updateOne({ _id: 1 }, { $[1]: { score: 50 } })
Drag options to blanks, or click blank then click option'
Ainc
Bmax
Cset
Dmin
Attempts:
3 left
💡 Hint
Common Mistakes
Using $max instead of $min will update only if the new value is greater.
Using $set will always update regardless of value.
2fill in blank
medium

Complete the code to update the field 'score' only if the new value is greater than the current value using the $max operator.

MongoDB
db.collection.updateOne({ _id: 2 }, { $[1]: { score: 80 } })
Drag options to blanks, or click blank then click option'
Amax
Bmin
Cset
Dinc
Attempts:
3 left
💡 Hint
Common Mistakes
Using $min will update only if the new value is smaller.
Using $set will overwrite the value regardless.
3fill in blank
hard

Fix the error in the update command to use the correct operator that updates 'level' only if the new value is greater.

MongoDB
db.collection.updateOne({ _id: 3 }, { $[1]: { level: 10 } })
Drag options to blanks, or click blank then click option'
Amin
Bmax
Cset
Dinc
Attempts:
3 left
💡 Hint
Common Mistakes
Using $min instead of $max.
Using $set which always updates.
4fill in blank
hard

Fill both blanks to update 'score' to 40 only if it is less than current, and 'rank' to 5 only if it is greater than current.

MongoDB
db.collection.updateOne({ _id: 4 }, { $[1]: { score: 40 }, $[2]: { rank: 5 } })
Drag options to blanks, or click blank then click option'
Amin
Bset
Cmax
Dinc
Attempts:
3 left
💡 Hint
Common Mistakes
Using $set for both fields updates unconditionally.
Mixing up $min and $max operators.
5fill in blank
hard

Fill all three blanks to update 'score' to 30 if less, 'level' to 15 if greater, and 'rank' to 2 if less.

MongoDB
db.collection.updateOne({ _id: 5 }, { $[1]: { score: 30, rank: 2 }, $[2]: { level: 15 }, $[3]: { extra: 100 } })
Drag options to blanks, or click blank then click option'
Amin
Bmax
Cset
Dinc
Attempts:
3 left
💡 Hint
Common Mistakes
Using $set for all fields ignores conditional updates.
Confusing which fields need $min or $max.