{ "description": "first-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": [ { "b": 0 }, { "b": 1 } ] }, { "_id": 3, "y": [ { "b": 5, "c": [ { "d": 2 } ] } ] } ] } ], "tests": [ { "description": "$ writes the element the filter matched", "operations": [ { "object": "collection0", "name": "updateOne", "arguments": { "filter": { "y.b": 3 }, "update": { "$set": { "y.$.b": 7 } } }, "expectResult": { "matchedCount": 1, "modifiedCount": 1, "upsertedCount": 0 } } ], "outcome": [ { "collectionName": "coll", "databaseName": "positional-corpus", "documents": [ { "_id": 1, "y": [ { "b": 7 }, { "b": 1 } ] }, { "_id": 2, "y": [ { "b": 0 }, { "b": 1 } ] }, { "_id": 3, "y": [ { "b": 5, "c": [ { "d": 2 } ] } ] } ] } ] }, { "description": "$ writes only the first match when several elements qualify", "operations": [ { "object": "collection0", "name": "deleteMany", "arguments": { "filter": {} } }, { "object": "collection0", "name": "insertMany", "arguments": { "documents": [ { "_id": 1, "y": [ { "b": 1 }, { "b": 1 }, { "b": 2 } ] } ] } }, { "object": "collection0", "name": "updateOne", "arguments": { "filter": { "y.b": 1 }, "update": { "$set": { "y.$.b": 7 } } }, "expectResult": { "matchedCount": 1, "modifiedCount": 1, "upsertedCount": 0 } } ], "outcome": [ { "collectionName": "coll", "databaseName": "positional-corpus", "documents": [ { "_id": 1, "y": [ { "b": 7 }, { "b": 1 }, { "b": 2 } ] } ] } ] }, { "description": "$ when the filter never touched the array is refused", "operations": [ { "object": "collection0", "name": "updateOne", "arguments": { "filter": { "_id": 1 }, "update": { "$set": { "y.$.b": 7 } } }, "expectError": { "isError": true, "errorCode": 2 } } ], "outcome": [ { "collectionName": "coll", "databaseName": "positional-corpus", "documents": [ { "_id": 1, "y": [ { "b": 3 }, { "b": 1 } ] }, { "_id": 2, "y": [ { "b": 0 }, { "b": 1 } ] }, { "_id": 3, "y": [ { "b": 5, "c": [ { "d": 2 } ] } ] } ] } ] }, { "description": "$inc through $", "operations": [ { "object": "collection0", "name": "updateOne", "arguments": { "filter": { "y.b": 3 }, "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": 1 } ] }, { "_id": 2, "y": [ { "b": 0 }, { "b": 1 } ] }, { "_id": 3, "y": [ { "b": 5, "c": [ { "d": 2 } ] } ] } ] } ] }, { "description": "$ as the leaf replaces the matched element", "operations": [ { "object": "collection0", "name": "updateOne", "arguments": { "filter": { "y.b": 3 }, "update": { "$set": { "y.$": { "replaced": true } } } }, "expectResult": { "matchedCount": 1, "modifiedCount": 1, "upsertedCount": 0 } } ], "outcome": [ { "collectionName": "coll", "databaseName": "positional-corpus", "documents": [ { "_id": 1, "y": [ { "replaced": true }, { "b": 1 } ] }, { "_id": 2, "y": [ { "b": 0 }, { "b": 1 } ] }, { "_id": 3, "y": [ { "b": 5, "c": [ { "d": 2 } ] } ] } ] } ] }, { "description": "$ reaching a field below the matched element", "operations": [ { "object": "collection0", "name": "updateOne", "arguments": { "filter": { "y.b": 5 }, "update": { "$set": { "y.$.c": [] } } }, "expectResult": { "matchedCount": 1, "modifiedCount": 1, "upsertedCount": 0 } } ], "outcome": [ { "collectionName": "coll", "databaseName": "positional-corpus", "documents": [ { "_id": 1, "y": [ { "b": 3 }, { "b": 1 } ] }, { "_id": 2, "y": [ { "b": 0 }, { "b": 1 } ] }, { "_id": 3, "y": [ { "b": 5, "c": [] } ] } ] } ] }, { "description": "$ with the filter matching on a different field of the element", "operations": [ { "object": "collection0", "name": "deleteMany", "arguments": { "filter": {} } }, { "object": "collection0", "name": "insertMany", "arguments": { "documents": [ { "_id": 1, "y": [ { "k": "a", "v": 1 }, { "k": "b", "v": 2 } ] } ] } }, { "object": "collection0", "name": "updateOne", "arguments": { "filter": { "y.k": "b" }, "update": { "$set": { "y.$.v": 9 } } }, "expectResult": { "matchedCount": 1, "modifiedCount": 1, "upsertedCount": 0 } } ], "outcome": [ { "collectionName": "coll", "databaseName": "positional-corpus", "documents": [ { "_id": 1, "y": [ { "k": "a", "v": 1 }, { "k": "b", "v": 9 } ] } ] } ] }, { "description": "updateMany with $ writes each document's own match", "operations": [ { "object": "collection0", "name": "updateMany", "arguments": { "filter": { "y.b": 1 }, "update": { "$set": { "y.$.b": 7 } } }, "expectResult": { "matchedCount": 2, "modifiedCount": 2, "upsertedCount": 0 } } ], "outcome": [ { "collectionName": "coll", "databaseName": "positional-corpus", "documents": [ { "_id": 1, "y": [ { "b": 3 }, { "b": 7 } ] }, { "_id": 2, "y": [ { "b": 0 }, { "b": 7 } ] }, { "_id": 3, "y": [ { "b": 5, "c": [ { "d": 2 } ] } ] } ] } ] }, { "description": "$ 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": { "y": 2 }, "update": { "$set": { "y.$": 9 } } }, "expectResult": { "matchedCount": 1, "modifiedCount": 1, "upsertedCount": 0 } } ], "outcome": [ { "collectionName": "coll", "databaseName": "positional-corpus", "documents": [ { "_id": 1, "y": [ 1, 9, 3 ] } ] } ] }, { "description": "$ in first position is refused", "operations": [ { "object": "collection0", "name": "updateOne", "arguments": { "filter": { "y.b": 3 }, "update": { "$set": { "$": 7 } } }, "expectError": { "isError": true, "errorCode": 2 } } ], "outcome": [ { "collectionName": "coll", "databaseName": "positional-corpus", "documents": [ { "_id": 1, "y": [ { "b": 3 }, { "b": 1 } ] }, { "_id": 2, "y": [ { "b": 0 }, { "b": 1 } ] }, { "_id": 3, "y": [ { "b": 5, "c": [ { "d": 2 } ] } ] } ] } ] }, { "description": "$ twice in one path is refused", "operations": [ { "object": "collection0", "name": "updateOne", "arguments": { "filter": { "y.b": 5 }, "update": { "$set": { "y.$.c.$.d": 0 } } }, "expectError": { "isError": true, "errorCode": 2 } } ], "outcome": [ { "collectionName": "coll", "databaseName": "positional-corpus", "documents": [ { "_id": 1, "y": [ { "b": 3 }, { "b": 1 } ] }, { "_id": 2, "y": [ { "b": 0 }, { "b": 1 } ] }, { "_id": 3, "y": [ { "b": 5, "c": [ { "d": 2 } ] } ] } ] } ] }, { "description": "$ on an upsert that inserts", "operations": [ { "object": "collection0", "name": "deleteMany", "arguments": { "filter": {} } }, { "object": "collection0", "name": "updateOne", "arguments": { "filter": { "y.b": 3 }, "update": { "$set": { "y.$.b": 7 } }, "upsert": true }, "expectError": { "isError": true, "errorCode": 2 } } ], "outcome": [ { "collectionName": "coll", "databaseName": "positional-corpus", "documents": [] } ] } ] }