0
0
MongoDBquery~10 mins

Array update with $[] all positional 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 all elements in the array field 'scores' by setting them to 100.

MongoDB
db.students.updateMany({}, { $set: { "scores[1]": 100 } })
Drag options to blanks, or click blank then click option'
A.$[]
B.$
C.[0]
D.$[0]
Attempts:
3 left
💡 Hint
Common Mistakes
Using .$ instead of .$[] updates only the first element.
Using array index like [0] updates only one element.
2fill in blank
medium

Complete the code to increment all elements in the 'grades' array by 5.

MongoDB
db.courses.updateMany({}, { $inc: { "grades[1]": 5 } })
Drag options to blanks, or click blank then click option'
A.$[1]
B.$[]
C.$
D.[0]
Attempts:
3 left
💡 Hint
Common Mistakes
Using .$ increments only the first element.
Using an index like [0] increments only one element.
3fill in blank
hard

Fix the error in the code to set all elements in 'ratings' array to 5.

MongoDB
db.products.updateMany({}, { $set: { "ratings[1]": 5 } })
Drag options to blanks, or click blank then click option'
A.[0]
B.$[elem]
C.$[]
D.$
Attempts:
3 left
💡 Hint
Common Mistakes
Using .$ updates only the first element, not all.
Using array index updates only one element.
4fill in blank
hard

Fill both blanks to multiply all elements in 'values' array by 2.

MongoDB
db.data.updateMany({}, { $mul: { "values[1]": [2] } })
Drag options to blanks, or click blank then click option'
A.$[]
B2
C3
D.$
Attempts:
3 left
💡 Hint
Common Mistakes
Using .$ updates only the first element.
Multiplying by 3 instead of 2 changes the result.
5fill in blank
hard

Fill both blanks to add 10 to all elements in 'scores' array and set 'updated' to true.

MongoDB
db.records.updateMany({}, { $inc: { "scores[1]": [2] }, $set: { "updated": true } })
Drag options to blanks, or click blank then click option'
A.$[]
B10
D.$
Attempts:
3 left
💡 Hint
Common Mistakes
Using .$ instead of .$[] updates only one element.
Adding wrong number instead of 10.
Using array operator on 'updated' field which is not an array.