0
0
MongoDBquery~10 mins

Array update with $[identifier] filtered 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 first matching element in the array.

MongoDB
db.collection.updateOne({ _id: 1 }, { $set: { 'items.$[[1]]': 10 } }, { arrayFilters: [{ '[1].type': 'fruit' }] })
Drag options to blanks, or click blank then click option'
Aitem
Belem
Cindex
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names in the update path and arrayFilters.
Using reserved keywords like 'value' as identifier.
2fill in blank
medium

Complete the code to increment the quantity of all matching array elements.

MongoDB
db.collection.updateMany({}, { $inc: { 'products.$[[1]].quantity': 1 } }, { arrayFilters: [{ '[1].status': 'available' }] })
Drag options to blanks, or click blank then click option'
Aindex
Bitem
Celem
Dprod
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatching identifier names.
Using invalid identifiers like 'index' which is not an object.
3fill in blank
hard

Fix the error in the array update by choosing the correct identifier.

MongoDB
db.collection.updateOne({ _id: 5 }, { $set: { 'orders.$[[1]].status': 'shipped' } }, { arrayFilters: [{ '[1].status': 'pending' }] })
Drag options to blanks, or click blank then click option'
Aitem
Bord
Corder
Dorders
Attempts:
3 left
💡 Hint
Common Mistakes
Using different identifiers in update path and arrayFilters.
Using plural names for single array elements.
4fill in blank
hard

Fill the blanks to update the price of items with quantity less than 5.

MongoDB
db.collection.updateMany({}, { $set: { 'inventory.$[[1]].price': 20 } }, { arrayFilters: [{ '[2].quantity': { $[3]: 5 } }] })
Drag options to blanks, or click blank then click option'
Ainv
Blt
Attempts:
3 left
💡 Hint
Common Mistakes
Using different identifiers in update path and arrayFilters.
Using wrong comparison operators like $gt instead of $lt.
5fill in blank
hard

Fill all three blanks to increment the score of players with level greater than 10.

MongoDB
db.players.updateMany({}, { $inc: { 'stats.$[[1]].score': [2] } }, { arrayFilters: [{ '[3].level': { $gt: 10 } }] })
Drag options to blanks, or click blank then click option'
Astat
B5
Dplayer
Attempts:
3 left
💡 Hint
Common Mistakes
Using different identifiers in update path and arrayFilters.
Using non-numeric values for increment.