But no documents are updated. What is the most likely cause?
medium
A. The $set operator cannot be used with $[i].
B. The query filter {_id: 1} is incorrect.
C. The identifier in arrayFilters does not match the one in the update query.
D. MongoDB does not support arrayFilters in updateOne.
Solution
Step 1: Check identifier consistency
The update uses $[i] but the arrayFilters uses item. These must match exactly.
Step 2: Understand effect of mismatch
Because the identifiers differ, MongoDB cannot apply the filter, so no elements are updated.
Final Answer:
The identifier in arrayFilters does not match the one in the update query. -> Option C
Quick Check:
Identifier names must match in update and arrayFilters [OK]
Hint: Match identifier names exactly in update and arrayFilters [OK]
Common Mistakes:
Using different names for identifier and filter variable
Assuming $set can't work with $[identifier]
Blaming query filter without checking arrayFilters
5. You have documents with an array field tasks where each task has status and priority. You want to update only tasks with status: 'pending' and priority greater than 5, setting their status to 'in-progress'. Which update command correctly does this?