{ "description": "all-positional", "schemaVersion": "1.4", "createEntities": [ { "client": { "id": "client0" } }, { "database": { "id": "database0", "client": "client0", "databaseName": "positional-corpus" } }, { "collection": { "id": "collection0", "database": "database0", "collectionName": "coll" } } ], "initialData": [ { "collectionName": "coll", "databaseName": "positional-corpus", "documents": [ { "_id": 1, "y": [ { "b": 3 }, { "b": 1 } ] }, { "_id": 2, "y": [] }, { "_id": 3, "y": [ { "c": [ { "d": 1 }, { "d": 2 } ] }, { "c": [ { "d": 3 } ] } ] } ] } ], "tests": [ { "description": "every element of the array is written", "operations": [ { "object": "collection0", "name": "updateOne", "arguments": { "filter": { "_id": 1 }, "update": { "$set": { "y.$[].b": 9 } } }, "expectResult": { "matchedCount": 1, "modifiedCount": 1, "upsertedCount": 0 } } ], "outcome": [ { "collectionName": "coll", "databaseName": "positional-corpus", "documents": [ { "_id": 1, "y": [ { "b": 9 }, { "b": 9 } ] }, { "_id": 2, "y": [] }, { "_id": 3, "y": [ { "c": [ { "d": 1 }, { "d": 2 } ] }, { "c": [ { "d": 3 } ] } ] } ] } ] }, { "description": "nested $[] is a cross-product over both levels", "operations": [ { "object": "collection0", "name": "updateOne", "arguments": { "filter": { "_id": 3 }, "update": { "$set": { "y.$[].c.$[].d": 0 } } }, "expectResult": { "matchedCount": 1, "modifiedCount": 1, "upsertedCount": 0 } } ], "outcome": [ { "collectionName": "coll", "databaseName": "positional-corpus", "documents": [ { "_id": 1, "y": [ { "b": 3 }, { "b": 1 } ] }, { "_id": 2, "y": [] }, { "_id": 3, "y": [ { "c": [ { "d": 0 }, { "d": 0 } ] }, { "c": [ { "d": 0 } ] } ] } ] } ] }, { "description": "$[] over an empty array", "operations": [ { "object": "collection0", "name": "updateOne", "arguments": { "filter": { "_id": 2 }, "update": { "$set": { "y.$[].b": 9 } } }, "expectResult": { "matchedCount": 1, "modifiedCount": 0, "upsertedCount": 0 } } ], "outcome": [ { "collectionName": "coll", "databaseName": "positional-corpus", "documents": [ { "_id": 1, "y": [ { "b": 3 }, { "b": 1 } ] }, { "_id": 2, "y": [] }, { "_id": 3, "y": [ { "c": [ { "d": 1 }, { "d": 2 } ] }, { "c": [ { "d": 3 } ] } ] } ] } ] }, { "description": "$inc through $[] adds to every element", "operations": [ { "object": "collection0", "name": "updateOne", "arguments": { "filter": { "_id": 1 }, "update": { "$inc": { "y.$[].b": 10 } } }, "expectResult": { "matchedCount": 1, "modifiedCount": 1, "upsertedCount": 0 } } ], "outcome": [ { "collectionName": "coll", "databaseName": "positional-corpus", "documents": [ { "_id": 1, "y": [ { "b": 13 }, { "b": 11 } ] }, { "_id": 2, "y": [] }, { "_id": 3, "y": [ { "c": [ { "d": 1 }, { "d": 2 } ] }, { "c": [ { "d": 3 } ] } ] } ] } ] }, { "description": "$[] as the leaf over an array of scalars", "operations": [ { "object": "collection0", "name": "deleteMany", "arguments": { "filter": {} } }, { "object": "collection0", "name": "insertMany", "arguments": { "documents": [ { "_id": 1, "y": [ 1, 2, 3 ] } ] } }, { "object": "collection0", "name": "updateOne", "arguments": { "filter": {}, "update": { "$set": { "y.$[]": 0 } } }, "expectResult": { "matchedCount": 1, "modifiedCount": 1, "upsertedCount": 0 } } ], "outcome": [ { "collectionName": "coll", "databaseName": "positional-corpus", "documents": [ { "_id": 1, "y": [ 0, 0, 0 ] } ] } ] }, { "description": "$unset through $[] removes a field from every element", "operations": [ { "object": "collection0", "name": "deleteMany", "arguments": { "filter": {} } }, { "object": "collection0", "name": "insertMany", "arguments": { "documents": [ { "_id": 1, "y": [ { "b": 1, "e": 1 }, { "b": 2, "e": 2 } ] } ] } }, { "object": "collection0", "name": "updateOne", "arguments": { "filter": {}, "update": { "$unset": { "y.$[].e": "" } } }, "expectResult": { "matchedCount": 1, "modifiedCount": 1, "upsertedCount": 0 } } ], "outcome": [ { "collectionName": "coll", "databaseName": "positional-corpus", "documents": [ { "_id": 1, "y": [ { "b": 1 }, { "b": 2 } ] } ] } ] }, { "description": "$[] where an element is not a document", "operations": [ { "object": "collection0", "name": "deleteMany", "arguments": { "filter": {} } }, { "object": "collection0", "name": "insertMany", "arguments": { "documents": [ { "_id": 1, "y": [ { "b": 1 }, 7 ] } ] } }, { "object": "collection0", "name": "updateOne", "arguments": { "filter": {}, "update": { "$set": { "y.$[].b": 9 } } }, "expectError": { "isError": true, "errorCode": 28 } } ], "outcome": [ { "collectionName": "coll", "databaseName": "positional-corpus", "documents": [ { "_id": 1, "y": [ { "b": 1 }, 7 ] } ] } ] }, { "description": "updateMany with $[] across every document", "operations": [ { "object": "collection0", "name": "updateMany", "arguments": { "filter": { "_id": { "$in": [ 1, 2 ] } }, "update": { "$set": { "y.$[].b": 9 } } }, "expectResult": { "matchedCount": 2, "modifiedCount": 1, "upsertedCount": 0 } } ], "outcome": [ { "collectionName": "coll", "databaseName": "positional-corpus", "documents": [ { "_id": 1, "y": [ { "b": 9 }, { "b": 9 } ] }, { "_id": 2, "y": [] }, { "_id": 3, "y": [ { "c": [ { "d": 1 }, { "d": 2 } ] }, { "c": [ { "d": 3 } ] } ] } ] } ] }, { "description": "$[] where the path does not exist", "operations": [ { "object": "collection0", "name": "deleteMany", "arguments": { "filter": {} } }, { "object": "collection0", "name": "insertMany", "arguments": { "documents": [ { "_id": 1, "z": 1 } ] } }, { "object": "collection0", "name": "updateOne", "arguments": { "filter": {}, "update": { "$set": { "y.$[].b": 9 } } }, "expectError": { "isError": true, "errorCode": 2 } } ], "outcome": [ { "collectionName": "coll", "databaseName": "positional-corpus", "documents": [ { "_id": 1, "z": 1 } ] } ] }, { "description": "$[] where the path is not an array", "operations": [ { "object": "collection0", "name": "deleteMany", "arguments": { "filter": {} } }, { "object": "collection0", "name": "insertMany", "arguments": { "documents": [ { "_id": 1, "y": 5 } ] } }, { "object": "collection0", "name": "updateOne", "arguments": { "filter": {}, "update": { "$set": { "y.$[].b": 9 } } }, "expectError": { "isError": true, "errorCode": 2 } } ], "outcome": [ { "collectionName": "coll", "databaseName": "positional-corpus", "documents": [ { "_id": 1, "y": 5 } ] } ] }, { "description": "$[] in first position is refused", "operations": [ { "object": "collection0", "name": "updateOne", "arguments": { "filter": { "_id": 1 }, "update": { "$set": { "$[]": 9 } } }, "expectError": { "isError": true, "errorCode": 2 } } ], "outcome": [ { "collectionName": "coll", "databaseName": "positional-corpus", "documents": [ { "_id": 1, "y": [ { "b": 3 }, { "b": 1 } ] }, { "_id": 2, "y": [] }, { "_id": 3, "y": [ { "c": [ { "d": 1 }, { "d": 2 } ] }, { "c": [ { "d": 3 } ] } ] } ] } ] }, { "description": "$[] combined with an identifier in one path", "operations": [ { "object": "collection0", "name": "updateOne", "arguments": { "filter": { "_id": 3 }, "update": { "$set": { "y.$[].c.$[j].d": 0 } }, "arrayFilters": [ { "j.d": 2 } ] }, "expectResult": { "matchedCount": 1, "modifiedCount": 1, "upsertedCount": 0 } } ], "outcome": [ { "collectionName": "coll", "databaseName": "positional-corpus", "documents": [ { "_id": 1, "y": [ { "b": 3 }, { "b": 1 } ] }, { "_id": 2, "y": [] }, { "_id": 3, "y": [ { "c": [ { "d": 1 }, { "d": 0 } ] }, { "c": [ { "d": 3 } ] } ] } ] } ] } ] }