Complete the code to update the first matching element in the array.
db.collection.updateOne({ _id: 1 }, { $set: { 'items.$[[1]]': 10 } }, { arrayFilters: [{ '[1].type': 'fruit' }] })The $[identifier] is a placeholder for the array element to update. Here, item is used as the identifier in both the update path and the array filter.
Complete the code to increment the quantity of all matching array elements.
db.collection.updateMany({}, { $inc: { 'products.$[[1]].quantity': 1 } }, { arrayFilters: [{ '[1].status': 'available' }] })The identifier prod is used to refer to each array element in products that matches the filter status: 'available'.
Fix the error in the array update by choosing the correct identifier.
db.collection.updateOne({ _id: 5 }, { $set: { 'orders.$[[1]].status': 'shipped' } }, { arrayFilters: [{ '[1].status': 'pending' }] })The identifier ord must be used consistently in both the update path and arrayFilters.
Fill the blanks to update the price of items with quantity less than 5.
db.collection.updateMany({}, { $set: { 'inventory.$[[1]].price': 20 } }, { arrayFilters: [{ '[2].quantity': { $[3]: 5 } }] })The identifier inv is used in both the update path and arrayFilters. The filter checks for quantity less than 5 using $lt.
Fill all three blanks to increment the score of players with level greater than 10.
db.players.updateMany({}, { $inc: { 'stats.$[[1]].score': [2] } }, { arrayFilters: [{ '[3].level': { $gt: 10 } }] })The identifier stat is used consistently in the update path and arrayFilters. The score is incremented by 5 for players with level greater than 10.