{ "_comment": [ "Inputs only. Expectations are measured -- see record.js.", "`$[]`, the all-positional operator. The pinned crud corpus contains no", "`$[]` case at all, which is half of why this directory exists: before", "the refusal landed, `$[]` overwrote the array it was meant to walk and", "nothing external would have noticed." ], "documents": [ { "_id": 1, "y": [{ "b": 3 }, { "b": 1 }] }, { "_id": 2, "y": [] }, { "_id": 3, "y": [{ "c": [{ "d": 1 }, { "d": 2 }] }, { "c": [{ "d": 3 }] }] } ], "cases": [ { "description": "every element of the array is written", "operation": "updateOne", "arguments": { "filter": { "_id": 1 }, "update": { "$set": { "y.$[].b": 9 } } } }, { "description": "nested $[] is a cross-product over both levels", "operation": "updateOne", "arguments": { "filter": { "_id": 3 }, "update": { "$set": { "y.$[].c.$[].d": 0 } } } }, { "description": "$[] over an empty array", "operation": "updateOne", "arguments": { "filter": { "_id": 2 }, "update": { "$set": { "y.$[].b": 9 } } } }, { "description": "$inc through $[] adds to every element", "operation": "updateOne", "arguments": { "filter": { "_id": 1 }, "update": { "$inc": { "y.$[].b": 10 } } } }, { "description": "$[] as the leaf over an array of scalars", "documents": [{ "_id": 1, "y": [1, 2, 3] }], "operation": "updateOne", "arguments": { "filter": {}, "update": { "$set": { "y.$[]": 0 } } } }, { "description": "$unset through $[] removes a field from every element", "documents": [{ "_id": 1, "y": [{ "b": 1, "e": 1 }, { "b": 2, "e": 2 }] }], "operation": "updateOne", "arguments": { "filter": {}, "update": { "$unset": { "y.$[].e": "" } } } }, { "description": "$[] where an element is not a document", "documents": [{ "_id": 1, "y": [{ "b": 1 }, 7] }], "operation": "updateOne", "arguments": { "filter": {}, "update": { "$set": { "y.$[].b": 9 } } } }, { "description": "updateMany with $[] across every document", "operation": "updateMany", "arguments": { "filter": { "_id": { "$in": [1, 2] } }, "update": { "$set": { "y.$[].b": 9 } } } }, { "description": "$[] where the path does not exist", "documents": [{ "_id": 1, "z": 1 }], "operation": "updateOne", "arguments": { "filter": {}, "update": { "$set": { "y.$[].b": 9 } } } }, { "description": "$[] where the path is not an array", "documents": [{ "_id": 1, "y": 5 }], "operation": "updateOne", "arguments": { "filter": {}, "update": { "$set": { "y.$[].b": 9 } } } }, { "description": "$[] in first position is refused", "operation": "updateOne", "arguments": { "filter": { "_id": 1 }, "update": { "$set": { "$[]": 9 } } } }, { "description": "$[] combined with an identifier in one path", "operation": "updateOne", "arguments": { "filter": { "_id": 3 }, "update": { "$set": { "y.$[].c.$[j].d": 0 } }, "arrayFilters": [{ "j.d": 2 }] } } ] }