diff --git a/src/bulk/common.ts b/src/bulk/common.ts index f424efe24b8..2e2da536cb1 100644 --- a/src/bulk/common.ts +++ b/src/bulk/common.ts @@ -977,7 +977,7 @@ export abstract class BulkOperationBase { // Fundamental error err: undefined, // check keys - checkKeys: typeof options.checkKeys === 'boolean' ? options.checkKeys : true + checkKeys: typeof options.checkKeys === 'boolean' ? options.checkKeys : false }; // bypass Validation diff --git a/src/cmap/commands.ts b/src/cmap/commands.ts index 0123399c9a2..88142199976 100644 --- a/src/cmap/commands.ts +++ b/src/cmap/commands.ts @@ -104,7 +104,7 @@ export class Query { this.ignoreUndefined = typeof options.ignoreUndefined === 'boolean' ? options.ignoreUndefined : false; this.maxBsonSize = options.maxBsonSize || 1024 * 1024 * 16; - this.checkKeys = typeof options.checkKeys === 'boolean' ? options.checkKeys : true; + this.checkKeys = typeof options.checkKeys === 'boolean' ? options.checkKeys : false; this.batchSize = this.numberToReturn; // Flags @@ -677,7 +677,7 @@ export class Msg { typeof options.serializeFunctions === 'boolean' ? options.serializeFunctions : false; this.ignoreUndefined = typeof options.ignoreUndefined === 'boolean' ? options.ignoreUndefined : false; - this.checkKeys = typeof options.checkKeys === 'boolean' ? options.checkKeys : true; + this.checkKeys = typeof options.checkKeys === 'boolean' ? options.checkKeys : false; this.maxBsonSize = options.maxBsonSize || 1024 * 1024 * 16; // flags diff --git a/src/operations/insert.ts b/src/operations/insert.ts index badfbf4cbf5..787e6faa98b 100644 --- a/src/operations/insert.ts +++ b/src/operations/insert.ts @@ -19,7 +19,7 @@ export class InsertOperation extends CommandOperation { constructor(ns: MongoDBNamespace, documents: Document[], options: BulkWriteOptions) { super(undefined, options); - this.options = { ...options, checkKeys: options.checkKeys ?? true }; + this.options = { ...options, checkKeys: options.checkKeys ?? false }; this.ns = ns; this.documents = documents; } diff --git a/test/functional/collection.test.js b/test/functional/collection.test.js index cdb6b115070..fd00b06bfb6 100644 --- a/test/functional/collection.test.js +++ b/test/functional/collection.test.js @@ -163,92 +163,6 @@ describe('Collection', function () { }); }); - it('should fail to insert due to illegal keys', function (done) { - db.createCollection('test_invalid_key_names', (err, collection) => { - // Legal inserts - collection.insertMany( - [{ hello: 'world' }, { hello: { hello: 'world' } }], - configuration.writeConcernMax(), - err => { - expect(err).to.not.exist; - - // Illegal insert for key - collection.insertOne({ $hello: 'world' }, configuration.writeConcernMax(), err => { - expect(err).to.be.an.instanceof(Error); - expect(err.message).to.equal("key $hello must not start with '$'"); - - collection.insertOne( - { hello: { $hello: 'world' } }, - configuration.writeConcernMax(), - err => { - expect(err).to.be.an.instanceof(Error); - expect(err.message).to.equal("key $hello must not start with '$'"); - - collection.insertOne( - { he$llo: 'world' }, - configuration.writeConcernMax(), - err => { - expect(err).to.not.exist; - - collection.insertOne( - { hello: { hell$o: 'world' } }, - configuration.writeConcernMax(), - err => { - expect(err).to.not.exist; - - collection.insertOne( - { '.hello': 'world' }, - configuration.writeConcernMax(), - err => { - expect(err).to.be.an.instanceof(Error); - expect(err.message).to.equal("key .hello must not contain '.'"); - - collection.insertOne( - { hello: { '.hello': 'world' } }, - configuration.writeConcernMax(), - err => { - expect(err).to.be.an.instanceof(Error); - expect(err.message).to.equal("key .hello must not contain '.'"); - - collection.insertOne( - { 'hello.': 'world' }, - configuration.writeConcernMax(), - err => { - expect(err).to.be.an.instanceof(Error); - expect(err.message).to.equal( - "key hello. must not contain '.'" - ); - - collection.insertOne( - { hello: { 'hello.': 'world' } }, - configuration.writeConcernMax(), - err => { - expect(err).to.be.an.instanceof(Error); - expect(err.message).to.equal( - "key hello. must not contain '.'" - ); - // Let's close the db - done(); - } - ); - } - ); - } - ); - } - ); - } - ); - } - ); - } - ); - }); - } - ); - }); - }); - it('should permit insert of dot and dollar keys if requested', function () { const collection = db.collection('test_invalid_key_names'); return Promise.all([ diff --git a/test/functional/insert.test.js b/test/functional/insert.test.js index 48d59f5090f..b30216a30f2 100644 --- a/test/functional/insert.test.js +++ b/test/functional/insert.test.js @@ -900,34 +900,6 @@ describe('Insert', function () { } }); - it('Should fail on insert due to key starting with $', { - // Add a tag that our runner can trigger on - // in this case we are setting that node needs to be higher than 0.10.X to run - metadata: { - requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } - }, - - test: function (done) { - var configuration = this.configuration; - var doc = { - _id: new ObjectId('4e886e687ff7ef5e00000162'), - $key: 'foreign' - }; - - var client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 }); - client.connect(function (err, client) { - var db = client.db(configuration.db); - var collection = db.collection('Should_fail_on_insert_due_to_key_starting_with'); - collection.insert(doc, configuration.writeConcernMax(), function (err, result) { - test.ok(err != null); - expect(result).to.not.exist; - - client.close(done); - }); - }); - } - }); - it('Should Correctly allow for control of serialization of functions on command level', { // Add a tag that our runner can trigger on // in this case we are setting that node needs to be higher than 0.10.X to run diff --git a/test/functional/unified-spec-runner/operations.ts b/test/functional/unified-spec-runner/operations.ts index d455b3229af..b5e82c960b6 100644 --- a/test/functional/unified-spec-runner/operations.ts +++ b/test/functional/unified-spec-runner/operations.ts @@ -251,7 +251,7 @@ operations.set('find', async ({ entities, operation }) => { operations.set('findOneAndReplace', async ({ entities, operation }) => { const collection = entities.getEntity('collection', operation.object); const { filter, replacement, ...opts } = operation.arguments; - return collection.findOneAndReplace(filter, replacement, translateOptions(opts)); + return (await collection.findOneAndReplace(filter, replacement, translateOptions(opts))).value; }); operations.set('findOneAndUpdate', async ({ entities, operation }) => { diff --git a/test/functional/unified-spec-runner/runner.ts b/test/functional/unified-spec-runner/runner.ts index f8fe77a533c..eb545670af6 100644 --- a/test/functional/unified-spec-runner/runner.ts +++ b/test/functional/unified-spec-runner/runner.ts @@ -152,7 +152,7 @@ export async function runUnifiedTest( expect(documents).to.have.lengthOf(collectionData.documents.length); for (const [expected, actual] of zip(collectionData.documents, documents)) { - expect(actual).to.include(expected, 'Test outcome did not match expected'); + expect(actual).to.deep.include(expected); } } } diff --git a/test/spec/crud/unified/bulkWrite-insertOne-dots_and_dollars.json b/test/spec/crud/unified/bulkWrite-insertOne-dots_and_dollars.json new file mode 100644 index 00000000000..92bbb1aaf25 --- /dev/null +++ b/test/spec/crud/unified/bulkWrite-insertOne-dots_and_dollars.json @@ -0,0 +1,374 @@ +{ + "description": "bulkWrite-insertOne-dots_and_dollars", + "schemaVersion": "1.0", + "createEntities": [ + { + "client": { + "id": "client0", + "observeEvents": [ + "commandStartedEvent" + ] + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "crud-tests" + } + }, + { + "collection": { + "id": "collection0", + "database": "database0", + "collectionName": "coll0" + } + } + ], + "initialData": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [] + } + ], + "tests": [ + { + "description": "Inserting document with top-level dollar-prefixed key on 5.0+ server", + "runOnRequirements": [ + { + "minServerVersion": "5.0" + } + ], + "operations": [ + { + "name": "bulkWrite", + "object": "collection0", + "arguments": { + "requests": [ + { + "insertOne": { + "document": { + "_id": 1, + "$a": 1 + } + } + } + ] + }, + "expectResult": { + "deletedCount": 0, + "insertedCount": 1, + "insertedIds": { + "$$unsetOrMatches": { + "0": 1 + } + }, + "matchedCount": 0, + "modifiedCount": 0, + "upsertedCount": 0, + "upsertedIds": {} + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "insert": "coll0", + "documents": [ + { + "_id": 1, + "$a": 1 + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "$a": 1 + } + ] + } + ] + }, + { + "description": "Inserting document with top-level dollar-prefixed key on pre-5.0 server yields server-side error", + "runOnRequirements": [ + { + "maxServerVersion": "4.99" + } + ], + "operations": [ + { + "name": "bulkWrite", + "object": "collection0", + "arguments": { + "requests": [ + { + "insertOne": { + "document": { + "_id": 1, + "$a": 1 + } + } + } + ] + }, + "expectError": { + "isClientError": false + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "insert": "coll0", + "documents": [ + { + "_id": 1, + "$a": 1 + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [] + } + ] + }, + { + "description": "Inserting document with top-level dotted key", + "operations": [ + { + "name": "bulkWrite", + "object": "collection0", + "arguments": { + "requests": [ + { + "insertOne": { + "document": { + "_id": 1, + "a.b": 1 + } + } + } + ] + }, + "expectResult": { + "deletedCount": 0, + "insertedCount": 1, + "insertedIds": { + "$$unsetOrMatches": { + "0": 1 + } + }, + "matchedCount": 0, + "modifiedCount": 0, + "upsertedCount": 0, + "upsertedIds": {} + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "insert": "coll0", + "documents": [ + { + "_id": 1, + "a.b": 1 + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "a.b": 1 + } + ] + } + ] + }, + { + "description": "Inserting document with dollar-prefixed key in embedded doc", + "operations": [ + { + "name": "bulkWrite", + "object": "collection0", + "arguments": { + "requests": [ + { + "insertOne": { + "document": { + "_id": 1, + "a": { + "$b": 1 + } + } + } + } + ] + }, + "expectResult": { + "deletedCount": 0, + "insertedCount": 1, + "insertedIds": { + "$$unsetOrMatches": { + "0": 1 + } + }, + "matchedCount": 0, + "modifiedCount": 0, + "upsertedCount": 0, + "upsertedIds": {} + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "insert": "coll0", + "documents": [ + { + "_id": 1, + "a": { + "$b": 1 + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "a": { + "$b": 1 + } + } + ] + } + ] + }, + { + "description": "Inserting document with dotted key in embedded doc", + "operations": [ + { + "name": "bulkWrite", + "object": "collection0", + "arguments": { + "requests": [ + { + "insertOne": { + "document": { + "_id": 1, + "a": { + "b.c": 1 + } + } + } + } + ] + }, + "expectResult": { + "deletedCount": 0, + "insertedCount": 1, + "insertedIds": { + "$$unsetOrMatches": { + "0": 1 + } + }, + "matchedCount": 0, + "modifiedCount": 0, + "upsertedCount": 0, + "upsertedIds": {} + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "insert": "coll0", + "documents": [ + { + "_id": 1, + "a": { + "b.c": 1 + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "a": { + "b.c": 1 + } + } + ] + } + ] + } + ] +} diff --git a/test/spec/crud/unified/bulkWrite-insertOne-dots_and_dollars.yml b/test/spec/crud/unified/bulkWrite-insertOne-dots_and_dollars.yml new file mode 100644 index 00000000000..de3885ac8ce --- /dev/null +++ b/test/spec/crud/unified/bulkWrite-insertOne-dots_and_dollars.yml @@ -0,0 +1,138 @@ +description: "bulkWrite-insertOne-dots_and_dollars" + +schemaVersion: "1.0" + +createEntities: + - client: + id: &client0 client0 + observeEvents: [ commandStartedEvent ] + - database: + id: &database0 database0 + client: *client0 + databaseName: &database0Name crud-tests + - collection: + id: &collection0 collection0 + database: *database0 + collectionName: &collection0Name coll0 + +initialData: &initialData + - collectionName: *collection0Name + databaseName: *database0Name + documents: [] + +tests: + - description: "Inserting document with top-level dollar-prefixed key on 5.0+ server" + runOnRequirements: + - minServerVersion: "5.0" + operations: + - name: bulkWrite + object: *collection0 + arguments: + requests: + - insertOne: + document: &dollarPrefixedKey { _id: 1, $a: 1 } + expectResult: &bulkWriteResult + deletedCount: 0 + insertedCount: 1 + insertedIds: { $$unsetOrMatches: { 0: 1 } } + matchedCount: 0 + modifiedCount: 0 + upsertedCount: 0 + upsertedIds: { } + expectEvents: &expectEventsDollarPrefixedKey + - client: *client0 + events: + - commandStartedEvent: + command: + insert: *collection0Name + documents: + - *dollarPrefixedKey + outcome: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - *dollarPrefixedKey + + - description: "Inserting document with top-level dollar-prefixed key on pre-5.0 server yields server-side error" + runOnRequirements: + - maxServerVersion: "4.99" + operations: + - name: bulkWrite + object: *collection0 + arguments: + requests: + - insertOne: + document: *dollarPrefixedKey + expectError: + isClientError: false + expectEvents: *expectEventsDollarPrefixedKey + outcome: *initialData + + - description: "Inserting document with top-level dotted key" + operations: + - name: bulkWrite + object: *collection0 + arguments: + requests: + - insertOne: + document: &dottedKey { _id: 1, a.b: 1 } + expectResult: *bulkWriteResult + expectEvents: + - client: *client0 + events: + - commandStartedEvent: + command: + insert: *collection0Name + documents: + - *dottedKey + outcome: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - *dottedKey + + - description: "Inserting document with dollar-prefixed key in embedded doc" + operations: + - name: bulkWrite + object: *collection0 + arguments: + requests: + - insertOne: + document: &dollarPrefixedKeyInEmbedded { _id: 1, a: { $b: 1 } } + expectResult: *bulkWriteResult + expectEvents: + - client: *client0 + events: + - commandStartedEvent: + command: + insert: *collection0Name + documents: + - *dollarPrefixedKeyInEmbedded + outcome: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - *dollarPrefixedKeyInEmbedded + + - description: "Inserting document with dotted key in embedded doc" + operations: + - name: bulkWrite + object: *collection0 + arguments: + requests: + - insertOne: + document: &dottedKeyInEmbedded { _id: 1, a: { b.c: 1 } } + expectResult: *bulkWriteResult + expectEvents: + - client: *client0 + events: + - commandStartedEvent: + command: + insert: *collection0Name + documents: + - *dottedKeyInEmbedded + outcome: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - *dottedKeyInEmbedded diff --git a/test/spec/crud/unified/bulkWrite-replaceOne-dots_and_dollars.json b/test/spec/crud/unified/bulkWrite-replaceOne-dots_and_dollars.json new file mode 100644 index 00000000000..fce647d8f4b --- /dev/null +++ b/test/spec/crud/unified/bulkWrite-replaceOne-dots_and_dollars.json @@ -0,0 +1,532 @@ +{ + "description": "bulkWrite-replaceOne-dots_and_dollars", + "schemaVersion": "1.0", + "createEntities": [ + { + "client": { + "id": "client0", + "observeEvents": [ + "commandStartedEvent" + ] + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "crud-tests" + } + }, + { + "collection": { + "id": "collection0", + "database": "database0", + "collectionName": "coll0" + } + } + ], + "initialData": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1 + } + ] + } + ], + "tests": [ + { + "description": "Replacing document with top-level dotted key on 3.6+ server", + "runOnRequirements": [ + { + "minServerVersion": "3.6" + } + ], + "operations": [ + { + "name": "bulkWrite", + "object": "collection0", + "arguments": { + "requests": [ + { + "replaceOne": { + "filter": { + "_id": 1 + }, + "replacement": { + "_id": 1, + "a.b": 1 + } + } + } + ] + }, + "expectResult": { + "deletedCount": 0, + "insertedCount": 0, + "insertedIds": { + "$$unsetOrMatches": {} + }, + "matchedCount": 1, + "modifiedCount": 1, + "upsertedCount": 0, + "upsertedIds": {} + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "update": "coll0", + "updates": [ + { + "q": { + "_id": 1 + }, + "u": { + "_id": 1, + "a.b": 1 + }, + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "a.b": 1 + } + ] + } + ] + }, + { + "description": "Replacing document with top-level dotted key on pre-3.6 server yields server-side error", + "runOnRequirements": [ + { + "maxServerVersion": "3.4.99" + } + ], + "operations": [ + { + "name": "bulkWrite", + "object": "collection0", + "arguments": { + "requests": [ + { + "replaceOne": { + "filter": { + "_id": 1 + }, + "replacement": { + "_id": 1, + "a.b": 1 + } + } + } + ] + }, + "expectError": { + "isClientError": false + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "update": "coll0", + "updates": [ + { + "q": { + "_id": 1 + }, + "u": { + "_id": 1, + "a.b": 1 + }, + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1 + } + ] + } + ] + }, + { + "description": "Replacing document with dollar-prefixed key in embedded doc on 5.0+ server", + "runOnRequirements": [ + { + "minServerVersion": "5.0" + } + ], + "operations": [ + { + "name": "bulkWrite", + "object": "collection0", + "arguments": { + "requests": [ + { + "replaceOne": { + "filter": { + "_id": 1 + }, + "replacement": { + "_id": 1, + "a": { + "$b": 1 + } + } + } + } + ] + }, + "expectResult": { + "deletedCount": 0, + "insertedCount": 0, + "insertedIds": { + "$$unsetOrMatches": {} + }, + "matchedCount": 1, + "modifiedCount": 1, + "upsertedCount": 0, + "upsertedIds": {} + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "update": "coll0", + "updates": [ + { + "q": { + "_id": 1 + }, + "u": { + "_id": 1, + "a": { + "$b": 1 + } + }, + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "a": { + "$b": 1 + } + } + ] + } + ] + }, + { + "description": "Replacing document with dollar-prefixed key in embedded doc on pre-5.0 server yields server-side error", + "runOnRequirements": [ + { + "maxServerVersion": "4.99" + } + ], + "operations": [ + { + "name": "bulkWrite", + "object": "collection0", + "arguments": { + "requests": [ + { + "replaceOne": { + "filter": { + "_id": 1 + }, + "replacement": { + "_id": 1, + "a": { + "$b": 1 + } + } + } + } + ] + }, + "expectError": { + "isClientError": false + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "update": "coll0", + "updates": [ + { + "q": { + "_id": 1 + }, + "u": { + "_id": 1, + "a": { + "$b": 1 + } + }, + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1 + } + ] + } + ] + }, + { + "description": "Replacing document with dotted key in embedded doc on 3.6+ server", + "runOnRequirements": [ + { + "minServerVersion": "3.6" + } + ], + "operations": [ + { + "name": "bulkWrite", + "object": "collection0", + "arguments": { + "requests": [ + { + "replaceOne": { + "filter": { + "_id": 1 + }, + "replacement": { + "_id": 1, + "a": { + "b.c": 1 + } + } + } + } + ] + }, + "expectResult": { + "deletedCount": 0, + "insertedCount": 0, + "insertedIds": { + "$$unsetOrMatches": {} + }, + "matchedCount": 1, + "modifiedCount": 1, + "upsertedCount": 0, + "upsertedIds": {} + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "update": "coll0", + "updates": [ + { + "q": { + "_id": 1 + }, + "u": { + "_id": 1, + "a": { + "b.c": 1 + } + }, + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "a": { + "b.c": 1 + } + } + ] + } + ] + }, + { + "description": "Replacing document with dotted key in embedded doc on pre-3.6 server yields server-side error", + "runOnRequirements": [ + { + "maxServerVersion": "3.4.99" + } + ], + "operations": [ + { + "name": "bulkWrite", + "object": "collection0", + "arguments": { + "requests": [ + { + "replaceOne": { + "filter": { + "_id": 1 + }, + "replacement": { + "_id": 1, + "a": { + "b.c": 1 + } + } + } + } + ] + }, + "expectError": { + "isClientError": false + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "update": "coll0", + "updates": [ + { + "q": { + "_id": 1 + }, + "u": { + "_id": 1, + "a": { + "b.c": 1 + } + }, + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1 + } + ] + } + ] + } + ] +} diff --git a/test/spec/crud/unified/bulkWrite-replaceOne-dots_and_dollars.yml b/test/spec/crud/unified/bulkWrite-replaceOne-dots_and_dollars.yml new file mode 100644 index 00000000000..65c414c1d6d --- /dev/null +++ b/test/spec/crud/unified/bulkWrite-replaceOne-dots_and_dollars.yml @@ -0,0 +1,165 @@ +description: "bulkWrite-replaceOne-dots_and_dollars" + +schemaVersion: "1.0" + +createEntities: + - client: + id: &client0 client0 + observeEvents: [ commandStartedEvent ] + - database: + id: &database0 database0 + client: *client0 + databaseName: &database0Name crud-tests + - collection: + id: &collection0 collection0 + database: *database0 + collectionName: &collection0Name coll0 + +initialData: &initialData + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - { _id: 1 } + +tests: + - description: "Replacing document with top-level dotted key on 3.6+ server" + runOnRequirements: + - minServerVersion: "3.6" + operations: + - name: bulkWrite + object: *collection0 + arguments: + requests: + - replaceOne: + filter: { _id: 1 } + replacement: &dottedKey { _id: 1, a.b: 1 } + expectResult: &bulkWriteResult + deletedCount: 0 + insertedCount: 0 + insertedIds: { $$unsetOrMatches: { } } + matchedCount: 1 + modifiedCount: 1 + upsertedCount: 0 + upsertedIds: { } + expectEvents: &expectEventsDottedKey + - client: *client0 + events: + - commandStartedEvent: + command: + update: *collection0Name + updates: + - q: { _id: 1 } + u: *dottedKey + multi: { $$unsetOrMatches: false } + upsert: { $$unsetOrMatches: false } + outcome: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - *dottedKey + + - description: "Replacing document with top-level dotted key on pre-3.6 server yields server-side error" + runOnRequirements: + - maxServerVersion: "3.4.99" + operations: + - name: bulkWrite + object: *collection0 + arguments: + requests: + - replaceOne: + filter: { _id: 1 } + replacement: *dottedKey + expectError: + isClientError: false + expectEvents: *expectEventsDottedKey + outcome: *initialData + + - description: "Replacing document with dollar-prefixed key in embedded doc on 5.0+ server" + runOnRequirements: + - minServerVersion: "5.0" + operations: + - name: bulkWrite + object: *collection0 + arguments: + requests: + - replaceOne: + filter: { _id: 1 } + replacement: &dollarPrefixedKeyInEmbedded { _id: 1, a: { $b: 1 } } + expectResult: *bulkWriteResult + expectEvents: &expectEventsDollarPrefixedKeyInEmbedded + - client: *client0 + events: + - commandStartedEvent: + command: + update: *collection0Name + updates: + - q: { _id: 1 } + u: *dollarPrefixedKeyInEmbedded + multi: { $$unsetOrMatches: false } + upsert: { $$unsetOrMatches: false } + outcome: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - *dollarPrefixedKeyInEmbedded + + - description: "Replacing document with dollar-prefixed key in embedded doc on pre-5.0 server yields server-side error" + runOnRequirements: + - maxServerVersion: "4.99" + operations: + - name: bulkWrite + object: *collection0 + arguments: + requests: + - replaceOne: + filter: { _id: 1 } + replacement: *dollarPrefixedKeyInEmbedded + expectError: + isClientError: false + expectEvents: *expectEventsDollarPrefixedKeyInEmbedded + outcome: *initialData + + - description: "Replacing document with dotted key in embedded doc on 3.6+ server" + runOnRequirements: + - minServerVersion: "3.6" + operations: + - name: bulkWrite + object: *collection0 + arguments: + requests: + - replaceOne: + filter: { _id: 1 } + replacement: &dottedKeyInEmbedded { _id: 1, a: { b.c: 1 } } + expectResult: *bulkWriteResult + expectEvents: &expectEventsDottedKeyInEmbedded + - client: *client0 + events: + - commandStartedEvent: + command: + update: *collection0Name + updates: + - q: { _id: 1 } + u: *dottedKeyInEmbedded + multi: { $$unsetOrMatches: false } + upsert: { $$unsetOrMatches: false } + outcome: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - *dottedKeyInEmbedded + + - description: "Replacing document with dotted key in embedded doc on pre-3.6 server yields server-side error" + runOnRequirements: + - maxServerVersion: "3.4.99" + operations: + - name: bulkWrite + object: *collection0 + arguments: + requests: + - replaceOne: + filter: { _id: 1 } + replacement: *dottedKeyInEmbedded + expectError: + isClientError: false + expectEvents: *expectEventsDottedKeyInEmbedded + outcome: *initialData diff --git a/test/spec/crud/unified/bulkWrite-updateMany-dots_and_dollars.json b/test/spec/crud/unified/bulkWrite-updateMany-dots_and_dollars.json new file mode 100644 index 00000000000..35a5cdd52a9 --- /dev/null +++ b/test/spec/crud/unified/bulkWrite-updateMany-dots_and_dollars.json @@ -0,0 +1,452 @@ +{ + "description": "bulkWrite-updateMany-dots_and_dollars", + "schemaVersion": "1.0", + "createEntities": [ + { + "client": { + "id": "client0", + "observeEvents": [ + "commandStartedEvent" + ] + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "crud-tests" + } + }, + { + "collection": { + "id": "collection0", + "database": "database0", + "collectionName": "coll0" + } + } + ], + "initialData": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "foo": {} + } + ] + } + ], + "tests": [ + { + "description": "Updating document to set top-level dollar-prefixed key on 5.0+ server", + "runOnRequirements": [ + { + "minServerVersion": "5.0" + } + ], + "operations": [ + { + "name": "bulkWrite", + "object": "collection0", + "arguments": { + "requests": [ + { + "updateMany": { + "filter": { + "_id": 1 + }, + "update": [ + { + "$replaceWith": { + "$setField": { + "field": { + "$literal": "$a" + }, + "value": 1, + "input": "$$ROOT" + } + } + } + ] + } + } + ] + }, + "expectResult": { + "deletedCount": 0, + "insertedCount": 0, + "insertedIds": { + "$$unsetOrMatches": {} + }, + "matchedCount": 1, + "modifiedCount": 1, + "upsertedCount": 0, + "upsertedIds": {} + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "update": "coll0", + "updates": [ + { + "q": { + "_id": 1 + }, + "u": [ + { + "$replaceWith": { + "$setField": { + "field": { + "$literal": "$a" + }, + "value": 1, + "input": "$$ROOT" + } + } + } + ], + "multi": true, + "upsert": { + "$$unsetOrMatches": false + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "foo": {}, + "$a": 1 + } + ] + } + ] + }, + { + "description": "Updating document to set top-level dotted key on 5.0+ server", + "runOnRequirements": [ + { + "minServerVersion": "5.0" + } + ], + "operations": [ + { + "name": "bulkWrite", + "object": "collection0", + "arguments": { + "requests": [ + { + "updateMany": { + "filter": { + "_id": 1 + }, + "update": [ + { + "$replaceWith": { + "$setField": { + "field": { + "$literal": "a.b" + }, + "value": 1, + "input": "$$ROOT" + } + } + } + ] + } + } + ] + }, + "expectResult": { + "deletedCount": 0, + "insertedCount": 0, + "insertedIds": { + "$$unsetOrMatches": {} + }, + "matchedCount": 1, + "modifiedCount": 1, + "upsertedCount": 0, + "upsertedIds": {} + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "update": "coll0", + "updates": [ + { + "q": { + "_id": 1 + }, + "u": [ + { + "$replaceWith": { + "$setField": { + "field": { + "$literal": "a.b" + }, + "value": 1, + "input": "$$ROOT" + } + } + } + ], + "multi": true, + "upsert": { + "$$unsetOrMatches": false + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "foo": {}, + "a.b": 1 + } + ] + } + ] + }, + { + "description": "Updating document to set dollar-prefixed key in embedded doc on 5.0+ server", + "runOnRequirements": [ + { + "minServerVersion": "5.0" + } + ], + "operations": [ + { + "name": "bulkWrite", + "object": "collection0", + "arguments": { + "requests": [ + { + "updateMany": { + "filter": { + "_id": 1 + }, + "update": [ + { + "$set": { + "foo": { + "$setField": { + "field": { + "$literal": "$a" + }, + "value": 1, + "input": "$foo" + } + } + } + } + ] + } + } + ] + }, + "expectResult": { + "deletedCount": 0, + "insertedCount": 0, + "insertedIds": { + "$$unsetOrMatches": {} + }, + "matchedCount": 1, + "modifiedCount": 1, + "upsertedCount": 0, + "upsertedIds": {} + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "update": "coll0", + "updates": [ + { + "q": { + "_id": 1 + }, + "u": [ + { + "$set": { + "foo": { + "$setField": { + "field": { + "$literal": "$a" + }, + "value": 1, + "input": "$foo" + } + } + } + } + ], + "multi": true, + "upsert": { + "$$unsetOrMatches": false + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "foo": { + "$a": 1 + } + } + ] + } + ] + }, + { + "description": "Updating document to set dotted key in embedded doc on 5.0+ server", + "runOnRequirements": [ + { + "minServerVersion": "5.0" + } + ], + "operations": [ + { + "name": "bulkWrite", + "object": "collection0", + "arguments": { + "requests": [ + { + "updateMany": { + "filter": { + "_id": 1 + }, + "update": [ + { + "$set": { + "foo": { + "$setField": { + "field": { + "$literal": "a.b" + }, + "value": 1, + "input": "$foo" + } + } + } + } + ] + } + } + ] + }, + "expectResult": { + "deletedCount": 0, + "insertedCount": 0, + "insertedIds": { + "$$unsetOrMatches": {} + }, + "matchedCount": 1, + "modifiedCount": 1, + "upsertedCount": 0, + "upsertedIds": {} + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "update": "coll0", + "updates": [ + { + "q": { + "_id": 1 + }, + "u": [ + { + "$set": { + "foo": { + "$setField": { + "field": { + "$literal": "a.b" + }, + "value": 1, + "input": "$foo" + } + } + } + } + ], + "multi": true, + "upsert": { + "$$unsetOrMatches": false + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "foo": { + "a.b": 1 + } + } + ] + } + ] + } + ] +} diff --git a/test/spec/crud/unified/bulkWrite-updateMany-dots_and_dollars.yml b/test/spec/crud/unified/bulkWrite-updateMany-dots_and_dollars.yml new file mode 100644 index 00000000000..68cebd09cf2 --- /dev/null +++ b/test/spec/crud/unified/bulkWrite-updateMany-dots_and_dollars.yml @@ -0,0 +1,150 @@ +description: "bulkWrite-updateMany-dots_and_dollars" + +schemaVersion: "1.0" + +createEntities: + - client: + id: &client0 client0 + observeEvents: [ commandStartedEvent ] + - database: + id: &database0 database0 + client: *client0 + databaseName: &database0Name crud-tests + - collection: + id: &collection0 collection0 + database: *database0 + collectionName: &collection0Name coll0 + +initialData: &initialData + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - { _id: 1, foo: {} } + +tests: + - description: "Updating document to set top-level dollar-prefixed key on 5.0+ server" + runOnRequirements: + - minServerVersion: "5.0" + operations: + - name: bulkWrite + object: *collection0 + arguments: + requests: + - updateMany: + filter: { _id: 1 } + update: &dollarPrefixedKey + - { $replaceWith: { $setField: { field: { $literal: $a }, value: 1, input: $$ROOT } } } + expectResult: &bulkWriteResult + deletedCount: 0 + insertedCount: 0 + insertedIds: { $$unsetOrMatches: { } } + matchedCount: 1 + modifiedCount: 1 + upsertedCount: 0 + upsertedIds: { } + expectEvents: + - client: *client0 + events: + - commandStartedEvent: + command: + update: *collection0Name + updates: + - q: { _id: 1 } + u: *dollarPrefixedKey + multi: true + upsert: { $$unsetOrMatches: false } + outcome: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - { _id: 1, foo: {}, $a: 1 } + + - description: "Updating document to set top-level dotted key on 5.0+ server" + runOnRequirements: + - minServerVersion: "5.0" + operations: + - name: bulkWrite + object: *collection0 + arguments: + requests: + - updateMany: + filter: { _id: 1 } + update: &dottedKey + - { $replaceWith: { $setField: { field: { $literal: a.b }, value: 1, input: $$ROOT } } } + expectResult: *bulkWriteResult + expectEvents: + - client: *client0 + events: + - commandStartedEvent: + command: + update: *collection0Name + updates: + - q: { _id: 1 } + u: *dottedKey + multi: true + upsert: { $$unsetOrMatches: false } + outcome: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - { _id: 1, foo: {}, a.b: 1 } + + - description: "Updating document to set dollar-prefixed key in embedded doc on 5.0+ server" + runOnRequirements: + - minServerVersion: "5.0" + operations: + - name: bulkWrite + object: *collection0 + arguments: + requests: + - updateMany: + filter: { _id: 1 } + update: &dollarPrefixedKeyInEmbedded + - { $set: { foo: { $setField: { field: { $literal: $a }, value: 1, input: $foo } } } } + expectResult: *bulkWriteResult + expectEvents: + - client: *client0 + events: + - commandStartedEvent: + command: + update: *collection0Name + updates: + - q: { _id: 1 } + u: *dollarPrefixedKeyInEmbedded + multi: true + upsert: { $$unsetOrMatches: false } + outcome: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - { _id: 1, foo: { $a: 1 } } + + - description: "Updating document to set dotted key in embedded doc on 5.0+ server" + runOnRequirements: + - minServerVersion: "5.0" + operations: + - name: bulkWrite + object: *collection0 + arguments: + requests: + - updateMany: + filter: { _id: 1 } + update: &dottedKeyInEmbedded + - { $set: { foo: { $setField: { field: { $literal: a.b }, value: 1, input: $foo } } } } + expectResult: *bulkWriteResult + expectEvents: + - client: *client0 + events: + - commandStartedEvent: + command: + update: *collection0Name + updates: + - q: { _id: 1 } + u: *dottedKeyInEmbedded + multi: true + upsert: { $$unsetOrMatches: false } + outcome: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - { _id: 1, foo: { a.b: 1 } } diff --git a/test/spec/crud/unified/bulkWrite-updateOne-dots_and_dollars.json b/test/spec/crud/unified/bulkWrite-updateOne-dots_and_dollars.json new file mode 100644 index 00000000000..cbbe113ce86 --- /dev/null +++ b/test/spec/crud/unified/bulkWrite-updateOne-dots_and_dollars.json @@ -0,0 +1,460 @@ +{ + "description": "bulkWrite-updateOne-dots_and_dollars", + "schemaVersion": "1.0", + "createEntities": [ + { + "client": { + "id": "client0", + "observeEvents": [ + "commandStartedEvent" + ] + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "crud-tests" + } + }, + { + "collection": { + "id": "collection0", + "database": "database0", + "collectionName": "coll0" + } + } + ], + "initialData": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "foo": {} + } + ] + } + ], + "tests": [ + { + "description": "Updating document to set top-level dollar-prefixed key on 5.0+ server", + "runOnRequirements": [ + { + "minServerVersion": "5.0" + } + ], + "operations": [ + { + "name": "bulkWrite", + "object": "collection0", + "arguments": { + "requests": [ + { + "updateOne": { + "filter": { + "_id": 1 + }, + "update": [ + { + "$replaceWith": { + "$setField": { + "field": { + "$literal": "$a" + }, + "value": 1, + "input": "$$ROOT" + } + } + } + ] + } + } + ] + }, + "expectResult": { + "deletedCount": 0, + "insertedCount": 0, + "insertedIds": { + "$$unsetOrMatches": {} + }, + "matchedCount": 1, + "modifiedCount": 1, + "upsertedCount": 0, + "upsertedIds": {} + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "update": "coll0", + "updates": [ + { + "q": { + "_id": 1 + }, + "u": [ + { + "$replaceWith": { + "$setField": { + "field": { + "$literal": "$a" + }, + "value": 1, + "input": "$$ROOT" + } + } + } + ], + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "foo": {}, + "$a": 1 + } + ] + } + ] + }, + { + "description": "Updating document to set top-level dotted key on 5.0+ server", + "runOnRequirements": [ + { + "minServerVersion": "5.0" + } + ], + "operations": [ + { + "name": "bulkWrite", + "object": "collection0", + "arguments": { + "requests": [ + { + "updateOne": { + "filter": { + "_id": 1 + }, + "update": [ + { + "$replaceWith": { + "$setField": { + "field": { + "$literal": "a.b" + }, + "value": 1, + "input": "$$ROOT" + } + } + } + ] + } + } + ] + }, + "expectResult": { + "deletedCount": 0, + "insertedCount": 0, + "insertedIds": { + "$$unsetOrMatches": {} + }, + "matchedCount": 1, + "modifiedCount": 1, + "upsertedCount": 0, + "upsertedIds": {} + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "update": "coll0", + "updates": [ + { + "q": { + "_id": 1 + }, + "u": [ + { + "$replaceWith": { + "$setField": { + "field": { + "$literal": "a.b" + }, + "value": 1, + "input": "$$ROOT" + } + } + } + ], + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "foo": {}, + "a.b": 1 + } + ] + } + ] + }, + { + "description": "Updating document to set dollar-prefixed key in embedded doc on 5.0+ server", + "runOnRequirements": [ + { + "minServerVersion": "5.0" + } + ], + "operations": [ + { + "name": "bulkWrite", + "object": "collection0", + "arguments": { + "requests": [ + { + "updateOne": { + "filter": { + "_id": 1 + }, + "update": [ + { + "$set": { + "foo": { + "$setField": { + "field": { + "$literal": "$a" + }, + "value": 1, + "input": "$foo" + } + } + } + } + ] + } + } + ] + }, + "expectResult": { + "deletedCount": 0, + "insertedCount": 0, + "insertedIds": { + "$$unsetOrMatches": {} + }, + "matchedCount": 1, + "modifiedCount": 1, + "upsertedCount": 0, + "upsertedIds": {} + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "update": "coll0", + "updates": [ + { + "q": { + "_id": 1 + }, + "u": [ + { + "$set": { + "foo": { + "$setField": { + "field": { + "$literal": "$a" + }, + "value": 1, + "input": "$foo" + } + } + } + } + ], + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "foo": { + "$a": 1 + } + } + ] + } + ] + }, + { + "description": "Updating document to set dotted key in embedded doc on 5.0+ server", + "runOnRequirements": [ + { + "minServerVersion": "5.0" + } + ], + "operations": [ + { + "name": "bulkWrite", + "object": "collection0", + "arguments": { + "requests": [ + { + "updateOne": { + "filter": { + "_id": 1 + }, + "update": [ + { + "$set": { + "foo": { + "$setField": { + "field": { + "$literal": "a.b" + }, + "value": 1, + "input": "$foo" + } + } + } + } + ] + } + } + ] + }, + "expectResult": { + "deletedCount": 0, + "insertedCount": 0, + "insertedIds": { + "$$unsetOrMatches": {} + }, + "matchedCount": 1, + "modifiedCount": 1, + "upsertedCount": 0, + "upsertedIds": {} + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "update": "coll0", + "updates": [ + { + "q": { + "_id": 1 + }, + "u": [ + { + "$set": { + "foo": { + "$setField": { + "field": { + "$literal": "a.b" + }, + "value": 1, + "input": "$foo" + } + } + } + } + ], + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "foo": { + "a.b": 1 + } + } + ] + } + ] + } + ] +} diff --git a/test/spec/crud/unified/bulkWrite-updateOne-dots_and_dollars.yml b/test/spec/crud/unified/bulkWrite-updateOne-dots_and_dollars.yml new file mode 100644 index 00000000000..c5a1662db10 --- /dev/null +++ b/test/spec/crud/unified/bulkWrite-updateOne-dots_and_dollars.yml @@ -0,0 +1,150 @@ +description: "bulkWrite-updateOne-dots_and_dollars" + +schemaVersion: "1.0" + +createEntities: + - client: + id: &client0 client0 + observeEvents: [ commandStartedEvent ] + - database: + id: &database0 database0 + client: *client0 + databaseName: &database0Name crud-tests + - collection: + id: &collection0 collection0 + database: *database0 + collectionName: &collection0Name coll0 + +initialData: &initialData + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - { _id: 1, foo: {} } + +tests: + - description: "Updating document to set top-level dollar-prefixed key on 5.0+ server" + runOnRequirements: + - minServerVersion: "5.0" + operations: + - name: bulkWrite + object: *collection0 + arguments: + requests: + - updateOne: + filter: { _id: 1 } + update: &dollarPrefixedKey + - { $replaceWith: { $setField: { field: { $literal: $a }, value: 1, input: $$ROOT } } } + expectResult: &bulkWriteResult + deletedCount: 0 + insertedCount: 0 + insertedIds: { $$unsetOrMatches: { } } + matchedCount: 1 + modifiedCount: 1 + upsertedCount: 0 + upsertedIds: { } + expectEvents: + - client: *client0 + events: + - commandStartedEvent: + command: + update: *collection0Name + updates: + - q: { _id: 1 } + u: *dollarPrefixedKey + multi: { $$unsetOrMatches: false } + upsert: { $$unsetOrMatches: false } + outcome: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - { _id: 1, foo: {}, $a: 1 } + + - description: "Updating document to set top-level dotted key on 5.0+ server" + runOnRequirements: + - minServerVersion: "5.0" + operations: + - name: bulkWrite + object: *collection0 + arguments: + requests: + - updateOne: + filter: { _id: 1 } + update: &dottedKey + - { $replaceWith: { $setField: { field: { $literal: a.b }, value: 1, input: $$ROOT } } } + expectResult: *bulkWriteResult + expectEvents: + - client: *client0 + events: + - commandStartedEvent: + command: + update: *collection0Name + updates: + - q: { _id: 1 } + u: *dottedKey + multi: { $$unsetOrMatches: false } + upsert: { $$unsetOrMatches: false } + outcome: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - { _id: 1, foo: {}, a.b: 1 } + + - description: "Updating document to set dollar-prefixed key in embedded doc on 5.0+ server" + runOnRequirements: + - minServerVersion: "5.0" + operations: + - name: bulkWrite + object: *collection0 + arguments: + requests: + - updateOne: + filter: { _id: 1 } + update: &dollarPrefixedKeyInEmbedded + - { $set: { foo: { $setField: { field: { $literal: $a }, value: 1, input: $foo } } } } + expectResult: *bulkWriteResult + expectEvents: + - client: *client0 + events: + - commandStartedEvent: + command: + update: *collection0Name + updates: + - q: { _id: 1 } + u: *dollarPrefixedKeyInEmbedded + multi: { $$unsetOrMatches: false } + upsert: { $$unsetOrMatches: false } + outcome: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - { _id: 1, foo: { $a: 1 } } + + - description: "Updating document to set dotted key in embedded doc on 5.0+ server" + runOnRequirements: + - minServerVersion: "5.0" + operations: + - name: bulkWrite + object: *collection0 + arguments: + requests: + - updateOne: + filter: { _id: 1 } + update: &dottedKeyInEmbedded + - { $set: { foo: { $setField: { field: { $literal: a.b }, value: 1, input: $foo } } } } + expectResult: *bulkWriteResult + expectEvents: + - client: *client0 + events: + - commandStartedEvent: + command: + update: *collection0Name + updates: + - q: { _id: 1 } + u: *dottedKeyInEmbedded + multi: { $$unsetOrMatches: false } + upsert: { $$unsetOrMatches: false } + outcome: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - { _id: 1, foo: { a.b: 1 } } diff --git a/test/spec/crud/unified/findOneAndReplace-dots_and_dollars.json b/test/spec/crud/unified/findOneAndReplace-dots_and_dollars.json new file mode 100644 index 00000000000..19ac447f842 --- /dev/null +++ b/test/spec/crud/unified/findOneAndReplace-dots_and_dollars.json @@ -0,0 +1,430 @@ +{ + "description": "findOneAndReplace-dots_and_dollars", + "schemaVersion": "1.0", + "createEntities": [ + { + "client": { + "id": "client0", + "observeEvents": [ + "commandStartedEvent" + ] + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "crud-tests" + } + }, + { + "collection": { + "id": "collection0", + "database": "database0", + "collectionName": "coll0" + } + } + ], + "initialData": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1 + } + ] + } + ], + "tests": [ + { + "description": "Replacing document with top-level dotted key on 3.6+ server", + "runOnRequirements": [ + { + "minServerVersion": "3.6" + } + ], + "operations": [ + { + "name": "findOneAndReplace", + "object": "collection0", + "arguments": { + "filter": { + "_id": 1 + }, + "replacement": { + "_id": 1, + "a.b": 1 + } + }, + "expectResult": { + "_id": 1 + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "findAndModify": "coll0", + "query": { + "_id": 1 + }, + "update": { + "_id": 1, + "a.b": 1 + }, + "new": { + "$$unsetOrMatches": false + } + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "a.b": 1 + } + ] + } + ] + }, + { + "description": "Replacing document with top-level dotted key on pre-3.6 server yields server-side error", + "runOnRequirements": [ + { + "maxServerVersion": "3.4.99" + } + ], + "operations": [ + { + "name": "findOneAndReplace", + "object": "collection0", + "arguments": { + "filter": { + "_id": 1 + }, + "replacement": { + "_id": 1, + "a.b": 1 + } + }, + "expectError": { + "isClientError": false + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "findAndModify": "coll0", + "query": { + "_id": 1 + }, + "update": { + "_id": 1, + "a.b": 1 + }, + "new": { + "$$unsetOrMatches": false + } + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1 + } + ] + } + ] + }, + { + "description": "Replacing document with dollar-prefixed key in embedded doc on 5.0+ server", + "runOnRequirements": [ + { + "minServerVersion": "5.0" + } + ], + "operations": [ + { + "name": "findOneAndReplace", + "object": "collection0", + "arguments": { + "filter": { + "_id": 1 + }, + "replacement": { + "_id": 1, + "a": { + "$b": 1 + } + } + }, + "expectResult": { + "_id": 1 + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "findAndModify": "coll0", + "query": { + "_id": 1 + }, + "update": { + "_id": 1, + "a": { + "$b": 1 + } + }, + "new": { + "$$unsetOrMatches": false + } + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "a": { + "$b": 1 + } + } + ] + } + ] + }, + { + "description": "Replacing document with dollar-prefixed key in embedded doc on pre-5.0 server yields server-side error", + "runOnRequirements": [ + { + "maxServerVersion": "4.99" + } + ], + "operations": [ + { + "name": "findOneAndReplace", + "object": "collection0", + "arguments": { + "filter": { + "_id": 1 + }, + "replacement": { + "_id": 1, + "a": { + "$b": 1 + } + } + }, + "expectError": { + "isClientError": false + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "findAndModify": "coll0", + "query": { + "_id": 1 + }, + "update": { + "_id": 1, + "a": { + "$b": 1 + } + }, + "new": { + "$$unsetOrMatches": false + } + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1 + } + ] + } + ] + }, + { + "description": "Replacing document with dotted key in embedded doc on 3.6+ server", + "runOnRequirements": [ + { + "minServerVersion": "3.6" + } + ], + "operations": [ + { + "name": "findOneAndReplace", + "object": "collection0", + "arguments": { + "filter": { + "_id": 1 + }, + "replacement": { + "_id": 1, + "a": { + "b.c": 1 + } + } + }, + "expectResult": { + "_id": 1 + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "findAndModify": "coll0", + "query": { + "_id": 1 + }, + "update": { + "_id": 1, + "a": { + "b.c": 1 + } + }, + "new": { + "$$unsetOrMatches": false + } + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "a": { + "b.c": 1 + } + } + ] + } + ] + }, + { + "description": "Replacing document with dotted key in embedded doc on pre-3.6 server yields server-side error", + "runOnRequirements": [ + { + "maxServerVersion": "3.4.99" + } + ], + "operations": [ + { + "name": "findOneAndReplace", + "object": "collection0", + "arguments": { + "filter": { + "_id": 1 + }, + "replacement": { + "_id": 1, + "a": { + "b.c": 1 + } + } + }, + "expectError": { + "isClientError": false + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "findAndModify": "coll0", + "query": { + "_id": 1 + }, + "update": { + "_id": 1, + "a": { + "b.c": 1 + } + }, + "new": { + "$$unsetOrMatches": false + } + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1 + } + ] + } + ] + } + ] +} diff --git a/test/spec/crud/unified/findOneAndReplace-dots_and_dollars.yml b/test/spec/crud/unified/findOneAndReplace-dots_and_dollars.yml new file mode 100644 index 00000000000..0823824cca6 --- /dev/null +++ b/test/spec/crud/unified/findOneAndReplace-dots_and_dollars.yml @@ -0,0 +1,140 @@ +description: "findOneAndReplace-dots_and_dollars" + +schemaVersion: "1.0" + +createEntities: + - client: + id: &client0 client0 + observeEvents: [ commandStartedEvent ] + - database: + id: &database0 database0 + client: *client0 + databaseName: &database0Name crud-tests + - collection: + id: &collection0 collection0 + database: *database0 + collectionName: &collection0Name coll0 + +initialData: &initialData + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - &initialDocument { _id: 1 } + +tests: + - description: "Replacing document with top-level dotted key on 3.6+ server" + runOnRequirements: + - minServerVersion: "3.6" + operations: + - name: findOneAndReplace + object: *collection0 + arguments: + filter: { _id: 1 } + replacement: &dottedKey { _id: 1, a.b: 1 } + expectResult: *initialDocument + expectEvents: &expectEventsDottedKey + - client: *client0 + events: + - commandStartedEvent: + command: + findAndModify: *collection0Name + query: { _id: 1 } + update: *dottedKey + new: { $$unsetOrMatches: false } + outcome: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - *dottedKey + + - description: "Replacing document with top-level dotted key on pre-3.6 server yields server-side error" + runOnRequirements: + - maxServerVersion: "3.4.99" + operations: + - name: findOneAndReplace + object: *collection0 + arguments: + filter: { _id: 1 } + replacement: *dottedKey + expectError: + isClientError: false + expectEvents: *expectEventsDottedKey + outcome: *initialData + + - description: "Replacing document with dollar-prefixed key in embedded doc on 5.0+ server" + runOnRequirements: + - minServerVersion: "5.0" + operations: + - name: findOneAndReplace + object: *collection0 + arguments: + filter: { _id: 1 } + replacement: &dollarPrefixedKeyInEmbedded { _id: 1, a: { $b: 1 } } + expectResult: *initialDocument + expectEvents: &expectEventsDollarPrefixedKeyInEmbedded + - client: *client0 + events: + - commandStartedEvent: + command: + findAndModify: *collection0Name + query: { _id: 1 } + update: *dollarPrefixedKeyInEmbedded + new: { $$unsetOrMatches: false } + outcome: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - *dollarPrefixedKeyInEmbedded + + - description: "Replacing document with dollar-prefixed key in embedded doc on pre-5.0 server yields server-side error" + runOnRequirements: + - maxServerVersion: "4.99" + operations: + - name: findOneAndReplace + object: *collection0 + arguments: + filter: { _id: 1 } + replacement: *dollarPrefixedKeyInEmbedded + expectError: + isClientError: false + expectEvents: *expectEventsDollarPrefixedKeyInEmbedded + outcome: *initialData + + - description: "Replacing document with dotted key in embedded doc on 3.6+ server" + runOnRequirements: + - minServerVersion: "3.6" + operations: + - name: findOneAndReplace + object: *collection0 + arguments: + filter: { _id: 1 } + replacement: &dottedKeyInEmbedded { _id: 1, a: { b.c: 1 } } + expectResult: *initialDocument + expectEvents: &expectEventsDottedKeyInEmbedded + - client: *client0 + events: + - commandStartedEvent: + command: + findAndModify: *collection0Name + query: { _id: 1 } + update: *dottedKeyInEmbedded + new: { $$unsetOrMatches: false } + outcome: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - *dottedKeyInEmbedded + + - description: "Replacing document with dotted key in embedded doc on pre-3.6 server yields server-side error" + runOnRequirements: + - maxServerVersion: "3.4.99" + operations: + - name: findOneAndReplace + object: *collection0 + arguments: + filter: { _id: 1 } + replacement: *dottedKeyInEmbedded + expectError: + isClientError: false + expectEvents: *expectEventsDottedKeyInEmbedded + outcome: *initialData diff --git a/test/spec/crud/unified/findOneAndUpdate-dots_and_dollars.json b/test/spec/crud/unified/findOneAndUpdate-dots_and_dollars.json new file mode 100644 index 00000000000..40eb5473928 --- /dev/null +++ b/test/spec/crud/unified/findOneAndUpdate-dots_and_dollars.json @@ -0,0 +1,380 @@ +{ + "description": "findOneAndUpdate-dots_and_dollars", + "schemaVersion": "1.0", + "createEntities": [ + { + "client": { + "id": "client0", + "observeEvents": [ + "commandStartedEvent" + ] + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "crud-tests" + } + }, + { + "collection": { + "id": "collection0", + "database": "database0", + "collectionName": "coll0" + } + } + ], + "initialData": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "foo": {} + } + ] + } + ], + "tests": [ + { + "description": "Updating document to set top-level dollar-prefixed key on 5.0+ server", + "runOnRequirements": [ + { + "minServerVersion": "5.0" + } + ], + "operations": [ + { + "name": "findOneAndUpdate", + "object": "collection0", + "arguments": { + "filter": { + "_id": 1 + }, + "update": [ + { + "$replaceWith": { + "$setField": { + "field": { + "$literal": "$a" + }, + "value": 1, + "input": "$$ROOT" + } + } + } + ] + }, + "expectResult": { + "_id": 1, + "foo": {} + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "findAndModify": "coll0", + "query": { + "_id": 1 + }, + "update": [ + { + "$replaceWith": { + "$setField": { + "field": { + "$literal": "$a" + }, + "value": 1, + "input": "$$ROOT" + } + } + } + ], + "new": { + "$$unsetOrMatches": false + } + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "foo": {}, + "$a": 1 + } + ] + } + ] + }, + { + "description": "Updating document to set top-level dotted key on 5.0+ server", + "runOnRequirements": [ + { + "minServerVersion": "5.0" + } + ], + "operations": [ + { + "name": "findOneAndUpdate", + "object": "collection0", + "arguments": { + "filter": { + "_id": 1 + }, + "update": [ + { + "$replaceWith": { + "$setField": { + "field": { + "$literal": "a.b" + }, + "value": 1, + "input": "$$ROOT" + } + } + } + ] + }, + "expectResult": { + "_id": 1, + "foo": {} + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "findAndModify": "coll0", + "query": { + "_id": 1 + }, + "update": [ + { + "$replaceWith": { + "$setField": { + "field": { + "$literal": "a.b" + }, + "value": 1, + "input": "$$ROOT" + } + } + } + ], + "new": { + "$$unsetOrMatches": false + } + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "foo": {}, + "a.b": 1 + } + ] + } + ] + }, + { + "description": "Updating document to set dollar-prefixed key in embedded doc on 5.0+ server", + "runOnRequirements": [ + { + "minServerVersion": "5.0" + } + ], + "operations": [ + { + "name": "findOneAndUpdate", + "object": "collection0", + "arguments": { + "filter": { + "_id": 1 + }, + "update": [ + { + "$set": { + "foo": { + "$setField": { + "field": { + "$literal": "$a" + }, + "value": 1, + "input": "$foo" + } + } + } + } + ] + }, + "expectResult": { + "_id": 1, + "foo": {} + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "findAndModify": "coll0", + "query": { + "_id": 1 + }, + "update": [ + { + "$set": { + "foo": { + "$setField": { + "field": { + "$literal": "$a" + }, + "value": 1, + "input": "$foo" + } + } + } + } + ], + "new": { + "$$unsetOrMatches": false + } + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "foo": { + "$a": 1 + } + } + ] + } + ] + }, + { + "description": "Updating document to set dotted key in embedded doc on 5.0+ server", + "runOnRequirements": [ + { + "minServerVersion": "5.0" + } + ], + "operations": [ + { + "name": "findOneAndUpdate", + "object": "collection0", + "arguments": { + "filter": { + "_id": 1 + }, + "update": [ + { + "$set": { + "foo": { + "$setField": { + "field": { + "$literal": "a.b" + }, + "value": 1, + "input": "$foo" + } + } + } + } + ] + }, + "expectResult": { + "_id": 1, + "foo": {} + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "findAndModify": "coll0", + "query": { + "_id": 1 + }, + "update": [ + { + "$set": { + "foo": { + "$setField": { + "field": { + "$literal": "a.b" + }, + "value": 1, + "input": "$foo" + } + } + } + } + ], + "new": { + "$$unsetOrMatches": false + } + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "foo": { + "a.b": 1 + } + } + ] + } + ] + } + ] +} diff --git a/test/spec/crud/unified/findOneAndUpdate-dots_and_dollars.yml b/test/spec/crud/unified/findOneAndUpdate-dots_and_dollars.yml new file mode 100644 index 00000000000..69b46a15bc3 --- /dev/null +++ b/test/spec/crud/unified/findOneAndUpdate-dots_and_dollars.yml @@ -0,0 +1,127 @@ +description: "findOneAndUpdate-dots_and_dollars" + +schemaVersion: "1.0" + +createEntities: + - client: + id: &client0 client0 + observeEvents: [ commandStartedEvent ] + - database: + id: &database0 database0 + client: *client0 + databaseName: &database0Name crud-tests + - collection: + id: &collection0 collection0 + database: *database0 + collectionName: &collection0Name coll0 + +initialData: &initialData + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - &initialDocument { _id: 1, foo: {} } + +tests: + - description: "Updating document to set top-level dollar-prefixed key on 5.0+ server" + runOnRequirements: + - minServerVersion: "5.0" + operations: + - name: findOneAndUpdate + object: *collection0 + arguments: + filter: { _id: 1 } + update: &dollarPrefixedKey + - { $replaceWith: { $setField: { field: { $literal: $a }, value: 1, input: $$ROOT } } } + expectResult: *initialDocument + expectEvents: + - client: *client0 + events: + - commandStartedEvent: + command: + findAndModify: *collection0Name + query: { _id: 1 } + update: *dollarPrefixedKey + new: { $$unsetOrMatches: false } + outcome: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - { _id: 1, foo: {}, $a: 1 } + + - description: "Updating document to set top-level dotted key on 5.0+ server" + runOnRequirements: + - minServerVersion: "5.0" + operations: + - name: findOneAndUpdate + object: *collection0 + arguments: + filter: { _id: 1 } + update: &dottedKey + - { $replaceWith: { $setField: { field: { $literal: a.b }, value: 1, input: $$ROOT } } } + expectResult: *initialDocument + expectEvents: + - client: *client0 + events: + - commandStartedEvent: + command: + findAndModify: *collection0Name + query: { _id: 1 } + update: *dottedKey + new: { $$unsetOrMatches: false } + outcome: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - { _id: 1, foo: {}, a.b: 1 } + + - description: "Updating document to set dollar-prefixed key in embedded doc on 5.0+ server" + runOnRequirements: + - minServerVersion: "5.0" + operations: + - name: findOneAndUpdate + object: *collection0 + arguments: + filter: { _id: 1 } + update: &dollarPrefixedKeyInEmbedded + - { $set: { foo: { $setField: { field: { $literal: $a }, value: 1, input: $foo } } } } + expectResult: *initialDocument + expectEvents: + - client: *client0 + events: + - commandStartedEvent: + command: + findAndModify: *collection0Name + query: { _id: 1 } + update: *dollarPrefixedKeyInEmbedded + new: { $$unsetOrMatches: false } + outcome: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - { _id: 1, foo: { $a: 1 } } + + - description: "Updating document to set dotted key in embedded doc on 5.0+ server" + runOnRequirements: + - minServerVersion: "5.0" + operations: + - name: findOneAndUpdate + object: *collection0 + arguments: + filter: { _id: 1 } + update: &dottedKeyInEmbedded + - { $set: { foo: { $setField: { field: { $literal: a.b }, value: 1, input: $foo } } } } + expectResult: *initialDocument + expectEvents: + - client: *client0 + events: + - commandStartedEvent: + command: + findAndModify: *collection0Name + query: { _id: 1 } + update: *dottedKeyInEmbedded + new: { $$unsetOrMatches: false } + outcome: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - { _id: 1, foo: { a.b: 1 } } diff --git a/test/spec/crud/unified/insertMany-dots_and_dollars.json b/test/spec/crud/unified/insertMany-dots_and_dollars.json new file mode 100644 index 00000000000..3b66ac06216 --- /dev/null +++ b/test/spec/crud/unified/insertMany-dots_and_dollars.json @@ -0,0 +1,334 @@ +{ + "description": "insertMany-dots_and_dollars", + "schemaVersion": "1.0", + "createEntities": [ + { + "client": { + "id": "client0", + "observeEvents": [ + "commandStartedEvent" + ] + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "crud-tests" + } + }, + { + "collection": { + "id": "collection0", + "database": "database0", + "collectionName": "coll0" + } + } + ], + "initialData": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [] + } + ], + "tests": [ + { + "description": "Inserting document with top-level dollar-prefixed key on 5.0+ server", + "runOnRequirements": [ + { + "minServerVersion": "5.0" + } + ], + "operations": [ + { + "name": "insertMany", + "object": "collection0", + "arguments": { + "documents": [ + { + "_id": 1, + "$a": 1 + } + ] + }, + "expectResult": { + "insertedCount": 1, + "insertedIds": { + "$$unsetOrMatches": { + "0": 1 + } + } + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "insert": "coll0", + "documents": [ + { + "_id": 1, + "$a": 1 + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "$a": 1 + } + ] + } + ] + }, + { + "description": "Inserting document with top-level dollar-prefixed key on pre-5.0 server yields server-side error", + "runOnRequirements": [ + { + "maxServerVersion": "4.99" + } + ], + "operations": [ + { + "name": "insertMany", + "object": "collection0", + "arguments": { + "documents": [ + { + "_id": 1, + "$a": 1 + } + ] + }, + "expectError": { + "isClientError": false + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "insert": "coll0", + "documents": [ + { + "_id": 1, + "$a": 1 + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [] + } + ] + }, + { + "description": "Inserting document with top-level dotted key", + "operations": [ + { + "name": "insertMany", + "object": "collection0", + "arguments": { + "documents": [ + { + "_id": 1, + "a.b": 1 + } + ] + }, + "expectResult": { + "insertedCount": 1, + "insertedIds": { + "$$unsetOrMatches": { + "0": 1 + } + } + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "insert": "coll0", + "documents": [ + { + "_id": 1, + "a.b": 1 + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "a.b": 1 + } + ] + } + ] + }, + { + "description": "Inserting document with dollar-prefixed key in embedded doc", + "operations": [ + { + "name": "insertMany", + "object": "collection0", + "arguments": { + "documents": [ + { + "_id": 1, + "a": { + "$b": 1 + } + } + ] + }, + "expectResult": { + "insertedCount": 1, + "insertedIds": { + "$$unsetOrMatches": { + "0": 1 + } + } + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "insert": "coll0", + "documents": [ + { + "_id": 1, + "a": { + "$b": 1 + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "a": { + "$b": 1 + } + } + ] + } + ] + }, + { + "description": "Inserting document with dotted key in embedded doc", + "operations": [ + { + "name": "insertMany", + "object": "collection0", + "arguments": { + "documents": [ + { + "_id": 1, + "a": { + "b.c": 1 + } + } + ] + }, + "expectResult": { + "insertedCount": 1, + "insertedIds": { + "$$unsetOrMatches": { + "0": 1 + } + } + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "insert": "coll0", + "documents": [ + { + "_id": 1, + "a": { + "b.c": 1 + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "a": { + "b.c": 1 + } + } + ] + } + ] + } + ] +} diff --git a/test/spec/crud/unified/insertMany-dots_and_dollars.yml b/test/spec/crud/unified/insertMany-dots_and_dollars.yml new file mode 100644 index 00000000000..63bbe16197d --- /dev/null +++ b/test/spec/crud/unified/insertMany-dots_and_dollars.yml @@ -0,0 +1,128 @@ +description: "insertMany-dots_and_dollars" + +schemaVersion: "1.0" + +createEntities: + - client: + id: &client0 client0 + observeEvents: [ commandStartedEvent ] + - database: + id: &database0 database0 + client: *client0 + databaseName: &database0Name crud-tests + - collection: + id: &collection0 collection0 + database: *database0 + collectionName: &collection0Name coll0 + +initialData: &initialData + - collectionName: *collection0Name + databaseName: *database0Name + documents: [] + +tests: + - description: "Inserting document with top-level dollar-prefixed key on 5.0+ server" + runOnRequirements: + - minServerVersion: "5.0" + operations: + - name: insertMany + object: *collection0 + arguments: + documents: + - &dollarPrefixedKey { _id: 1, $a: 1 } + expectResult: &insertResult + insertedCount: 1 + insertedIds: { $$unsetOrMatches: { 0: 1 } } + expectEvents: &expectEventsDollarPrefixedKey + - client: *client0 + events: + - commandStartedEvent: + command: + insert: *collection0Name + documents: + - *dollarPrefixedKey + outcome: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - *dollarPrefixedKey + + - description: "Inserting document with top-level dollar-prefixed key on pre-5.0 server yields server-side error" + runOnRequirements: + - maxServerVersion: "4.99" + operations: + - name: insertMany + object: *collection0 + arguments: + documents: + - *dollarPrefixedKey + expectError: + isClientError: false + expectEvents: *expectEventsDollarPrefixedKey + outcome: *initialData + + - description: "Inserting document with top-level dotted key" + operations: + - name: insertMany + object: *collection0 + arguments: + documents: + - &dottedKey { _id: 1, a.b: 1 } + expectResult: *insertResult + expectEvents: + - client: *client0 + events: + - commandStartedEvent: + command: + insert: *collection0Name + documents: + - *dottedKey + outcome: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - *dottedKey + + - description: "Inserting document with dollar-prefixed key in embedded doc" + operations: + - name: insertMany + object: *collection0 + arguments: + documents: + - &dollarPrefixedKeyInEmbedded { _id: 1, a: { $b: 1 } } + expectResult: *insertResult + expectEvents: + - client: *client0 + events: + - commandStartedEvent: + command: + insert: *collection0Name + documents: + - *dollarPrefixedKeyInEmbedded + outcome: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - *dollarPrefixedKeyInEmbedded + + - description: "Inserting document with dotted key in embedded doc" + operations: + - name: insertMany + object: *collection0 + arguments: + documents: + - &dottedKeyInEmbedded { _id: 1, a: { b.c: 1 } } + expectResult: *insertResult + expectEvents: + - client: *client0 + events: + - commandStartedEvent: + command: + insert: *collection0Name + documents: + - *dottedKeyInEmbedded + outcome: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - *dottedKeyInEmbedded diff --git a/test/spec/crud/unified/insertOne-dots_and_dollars.json b/test/spec/crud/unified/insertOne-dots_and_dollars.json new file mode 100644 index 00000000000..4b9fbfb80b4 --- /dev/null +++ b/test/spec/crud/unified/insertOne-dots_and_dollars.json @@ -0,0 +1,600 @@ +{ + "description": "insertOne-dots_and_dollars", + "schemaVersion": "1.0", + "createEntities": [ + { + "client": { + "id": "client0", + "observeEvents": [ + "commandStartedEvent" + ] + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "crud-tests" + } + }, + { + "collection": { + "id": "collection0", + "database": "database0", + "collectionName": "coll0" + } + }, + { + "collection": { + "id": "collection1", + "database": "database0", + "collectionName": "coll1", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + } + } + } + ], + "initialData": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [] + } + ], + "tests": [ + { + "description": "Inserting document with top-level dollar-prefixed key on 5.0+ server", + "runOnRequirements": [ + { + "minServerVersion": "5.0" + } + ], + "operations": [ + { + "name": "insertOne", + "object": "collection0", + "arguments": { + "document": { + "_id": 1, + "$a": 1 + } + }, + "expectResult": { + "insertedId": { + "$$unsetOrMatches": 1 + } + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "insert": "coll0", + "documents": [ + { + "_id": 1, + "$a": 1 + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "$a": 1 + } + ] + } + ] + }, + { + "description": "Inserting document with top-level dollar-prefixed key on pre-5.0 server yields server-side error", + "runOnRequirements": [ + { + "maxServerVersion": "4.99" + } + ], + "operations": [ + { + "name": "insertOne", + "object": "collection0", + "arguments": { + "document": { + "_id": 1, + "$a": 1 + } + }, + "expectError": { + "isClientError": false + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "insert": "coll0", + "documents": [ + { + "_id": 1, + "$a": 1 + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [] + } + ] + }, + { + "description": "Inserting document with top-level dotted key", + "operations": [ + { + "name": "insertOne", + "object": "collection0", + "arguments": { + "document": { + "_id": 1, + "a.b": 1 + } + }, + "expectResult": { + "insertedId": { + "$$unsetOrMatches": 1 + } + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "insert": "coll0", + "documents": [ + { + "_id": 1, + "a.b": 1 + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "a.b": 1 + } + ] + } + ] + }, + { + "description": "Inserting document with dollar-prefixed key in embedded doc", + "operations": [ + { + "name": "insertOne", + "object": "collection0", + "arguments": { + "document": { + "_id": 1, + "a": { + "$b": 1 + } + } + }, + "expectResult": { + "insertedId": { + "$$unsetOrMatches": 1 + } + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "insert": "coll0", + "documents": [ + { + "_id": 1, + "a": { + "$b": 1 + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "a": { + "$b": 1 + } + } + ] + } + ] + }, + { + "description": "Inserting document with dotted key in embedded doc", + "operations": [ + { + "name": "insertOne", + "object": "collection0", + "arguments": { + "document": { + "_id": 1, + "a": { + "b.c": 1 + } + } + }, + "expectResult": { + "insertedId": { + "$$unsetOrMatches": 1 + } + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "insert": "coll0", + "documents": [ + { + "_id": 1, + "a": { + "b.c": 1 + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "a": { + "b.c": 1 + } + } + ] + } + ] + }, + { + "description": "Inserting document with dollar-prefixed key in _id yields server-side error", + "operations": [ + { + "name": "insertOne", + "object": "collection0", + "arguments": { + "document": { + "_id": { + "$a": 1 + } + } + }, + "expectError": { + "isClientError": false + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "insert": "coll0", + "documents": [ + { + "_id": { + "$a": 1 + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [] + } + ] + }, + { + "description": "Inserting document with dotted key in _id on 3.6+ server", + "runOnRequirements": [ + { + "minServerVersion": "3.6" + } + ], + "operations": [ + { + "name": "insertOne", + "object": "collection0", + "arguments": { + "document": { + "_id": { + "a.b": 1 + } + } + }, + "expectResult": { + "insertedId": { + "$$unsetOrMatches": { + "a.b": 1 + } + } + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "insert": "coll0", + "documents": [ + { + "_id": { + "a.b": 1 + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": { + "a.b": 1 + } + } + ] + } + ] + }, + { + "description": "Inserting document with dotted key in _id on pre-3.6 server yields server-side error", + "runOnRequirements": [ + { + "maxServerVersion": "3.4.99" + } + ], + "operations": [ + { + "name": "insertOne", + "object": "collection0", + "arguments": { + "document": { + "_id": { + "a.b": 1 + } + } + }, + "expectError": { + "isClientError": false + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "insert": "coll0", + "documents": [ + { + "_id": { + "a.b": 1 + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [] + } + ] + }, + { + "description": "Inserting document with DBRef-like keys", + "operations": [ + { + "name": "insertOne", + "object": "collection0", + "arguments": { + "document": { + "_id": 1, + "a": { + "$db": "foo" + } + } + }, + "expectResult": { + "insertedId": { + "$$unsetOrMatches": 1 + } + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "insert": "coll0", + "documents": [ + { + "_id": 1, + "a": { + "$db": "foo" + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "a": { + "$db": "foo" + } + } + ] + } + ] + }, + { + "description": "Unacknowledged write using dollar-prefixed or dotted keys may be silently rejected on pre-5.0 server", + "runOnRequirements": [ + { + "maxServerVersion": "4.99" + } + ], + "operations": [ + { + "name": "insertOne", + "object": "collection1", + "arguments": { + "document": { + "_id": { + "$a": 1 + } + } + }, + "expectResult": { + "acknowledged": { + "$$unsetOrMatches": false + } + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "insert": "coll1", + "documents": [ + { + "_id": { + "$a": 1 + } + } + ], + "writeConcern": { + "w": 0 + } + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [] + } + ] + } + ] +} diff --git a/test/spec/crud/unified/insertOne-dots_and_dollars.yml b/test/spec/crud/unified/insertOne-dots_and_dollars.yml new file mode 100644 index 00000000000..f23fec2d51a --- /dev/null +++ b/test/spec/crud/unified/insertOne-dots_and_dollars.yml @@ -0,0 +1,235 @@ +description: "insertOne-dots_and_dollars" + +schemaVersion: "1.0" + +createEntities: + - client: + id: &client0 client0 + observeEvents: [ commandStartedEvent ] + - database: + id: &database0 database0 + client: *client0 + databaseName: &database0Name crud-tests + - collection: + id: &collection0 collection0 + database: *database0 + collectionName: &collection0Name coll0 + - collection: + id: &collection1 collection1 + database: *database0 + collectionName: &collection1Name coll1 + collectionOptions: + writeConcern: { w: 0 } + +initialData: &initialData + - collectionName: *collection0Name + databaseName: *database0Name + documents: [] + +tests: + - description: "Inserting document with top-level dollar-prefixed key on 5.0+ server" + runOnRequirements: + - minServerVersion: "5.0" + operations: + - name: insertOne + object: *collection0 + arguments: + document: &dollarPrefixedKey { _id: 1, $a: 1 } + expectResult: &insertResult + insertedId: { $$unsetOrMatches: 1 } + expectEvents: &expectEventsDollarPrefixedKey + - client: *client0 + events: + - commandStartedEvent: + command: + insert: *collection0Name + documents: + - *dollarPrefixedKey + outcome: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - *dollarPrefixedKey + + - description: "Inserting document with top-level dollar-prefixed key on pre-5.0 server yields server-side error" + runOnRequirements: + - maxServerVersion: "4.99" + operations: + - name: insertOne + object: *collection0 + arguments: + document: *dollarPrefixedKey + expectError: + isClientError: false + expectEvents: *expectEventsDollarPrefixedKey + outcome: *initialData + + - description: "Inserting document with top-level dotted key" + operations: + - name: insertOne + object: *collection0 + arguments: + document: &dottedKey { _id: 1, a.b: 1 } + expectResult: *insertResult + expectEvents: + - client: *client0 + events: + - commandStartedEvent: + command: + insert: *collection0Name + documents: + - *dottedKey + outcome: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - *dottedKey + + - description: "Inserting document with dollar-prefixed key in embedded doc" + operations: + - name: insertOne + object: *collection0 + arguments: + document: &dollarPrefixedKeyInEmbedded { _id: 1, a: { $b: 1 } } + expectResult: *insertResult + expectEvents: + - client: *client0 + events: + - commandStartedEvent: + command: + insert: *collection0Name + documents: + - *dollarPrefixedKeyInEmbedded + outcome: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - *dollarPrefixedKeyInEmbedded + + - description: "Inserting document with dotted key in embedded doc" + operations: + - name: insertOne + object: *collection0 + arguments: + document: &dottedKeyInEmbedded { _id: 1, a: { b.c: 1 } } + expectResult: *insertResult + expectEvents: + - client: *client0 + events: + - commandStartedEvent: + command: + insert: *collection0Name + documents: + - *dottedKeyInEmbedded + outcome: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - *dottedKeyInEmbedded + + - description: "Inserting document with dollar-prefixed key in _id yields server-side error" + # Note: 5.0+ did not remove restrictions on dollar-prefixed keys in _id documents + operations: + - name: insertOne + object: *collection0 + arguments: + document: &dollarPrefixedKeyInId { _id: { $a: 1 } } + expectError: + isClientError: false + expectEvents: + - client: *client0 + events: + - commandStartedEvent: + command: + insert: *collection0Name + documents: + - *dollarPrefixedKeyInId + outcome: *initialData + + - description: "Inserting document with dotted key in _id on 3.6+ server" + runOnRequirements: + - minServerVersion: "3.6" + operations: + - name: insertOne + object: *collection0 + arguments: + document: &dottedKeyInId { _id: { a.b: 1 } } + expectResult: + insertedId: { $$unsetOrMatches: { a.b: 1 } } + expectEvents: &expectEventsDottedKeyInId + - client: *client0 + events: + - commandStartedEvent: + command: + insert: *collection0Name + documents: + - *dottedKeyInId + outcome: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - *dottedKeyInId + + - description: "Inserting document with dotted key in _id on pre-3.6 server yields server-side error" + runOnRequirements: + - maxServerVersion: "3.4.99" + operations: + - name: insertOne + object: *collection0 + arguments: + document: *dottedKeyInId + expectError: + isClientError: false + expectEvents: *expectEventsDottedKeyInId + outcome: *initialData + + - description: "Inserting document with DBRef-like keys" + operations: + - name: insertOne + object: *collection0 + arguments: + # Note: an incomplete DBRef document may cause issues loading the test + # file with an Extended JSON parser, since the presence of one DBRef + # key may cause the parser to require others and/or enforce expected + # types (e.g. $ref and $db must be strings). + # + # Using "$db" here works for libmongoc so long as it's a string type; + # however, neither $ref nor $id would be accepted on their own. + # + # See https://github.com/mongodb/specifications/blob/master/source/extended-json.rst#parsers + document: &dbrefLikeKey { _id: 1, a: { $db: "foo" } } + expectResult: *insertResult + expectEvents: + - client: *client0 + events: + - commandStartedEvent: + command: + insert: *collection0Name + documents: + - *dbrefLikeKey + outcome: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - *dbrefLikeKey + + - description: "Unacknowledged write using dollar-prefixed or dotted keys may be silently rejected on pre-5.0 server" + runOnRequirements: + - maxServerVersion: "4.99" + operations: + - name: insertOne + object: *collection1 + arguments: + document: *dollarPrefixedKeyInId + expectResult: + acknowledged: { $$unsetOrMatches: false } + expectEvents: + - client: *client0 + events: + - commandStartedEvent: + command: + insert: *collection1Name + documents: + - *dollarPrefixedKeyInId + writeConcern: { w: 0 } + outcome: *initialData diff --git a/test/spec/crud/unified/replaceOne-dots_and_dollars.json b/test/spec/crud/unified/replaceOne-dots_and_dollars.json new file mode 100644 index 00000000000..d5003dc5ea4 --- /dev/null +++ b/test/spec/crud/unified/replaceOne-dots_and_dollars.json @@ -0,0 +1,567 @@ +{ + "description": "replaceOne-dots_and_dollars", + "schemaVersion": "1.0", + "createEntities": [ + { + "client": { + "id": "client0", + "observeEvents": [ + "commandStartedEvent" + ] + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "crud-tests" + } + }, + { + "collection": { + "id": "collection0", + "database": "database0", + "collectionName": "coll0" + } + }, + { + "collection": { + "id": "collection1", + "database": "database0", + "collectionName": "coll1", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + } + } + } + ], + "initialData": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1 + } + ] + } + ], + "tests": [ + { + "description": "Replacing document with top-level dotted key on 3.6+ server", + "runOnRequirements": [ + { + "minServerVersion": "3.6" + } + ], + "operations": [ + { + "name": "replaceOne", + "object": "collection0", + "arguments": { + "filter": { + "_id": 1 + }, + "replacement": { + "_id": 1, + "a.b": 1 + } + }, + "expectResult": { + "matchedCount": 1, + "modifiedCount": 1, + "upsertedCount": 0 + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "update": "coll0", + "updates": [ + { + "q": { + "_id": 1 + }, + "u": { + "_id": 1, + "a.b": 1 + }, + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "a.b": 1 + } + ] + } + ] + }, + { + "description": "Replacing document with top-level dotted key on pre-3.6 server yields server-side error", + "runOnRequirements": [ + { + "maxServerVersion": "3.4.99" + } + ], + "operations": [ + { + "name": "replaceOne", + "object": "collection0", + "arguments": { + "filter": { + "_id": 1 + }, + "replacement": { + "_id": 1, + "a.b": 1 + } + }, + "expectError": { + "isClientError": false + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "update": "coll0", + "updates": [ + { + "q": { + "_id": 1 + }, + "u": { + "_id": 1, + "a.b": 1 + }, + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1 + } + ] + } + ] + }, + { + "description": "Replacing document with dollar-prefixed key in embedded doc on 5.0+ server", + "runOnRequirements": [ + { + "minServerVersion": "5.0" + } + ], + "operations": [ + { + "name": "replaceOne", + "object": "collection0", + "arguments": { + "filter": { + "_id": 1 + }, + "replacement": { + "_id": 1, + "a": { + "$b": 1 + } + } + }, + "expectResult": { + "matchedCount": 1, + "modifiedCount": 1, + "upsertedCount": 0 + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "update": "coll0", + "updates": [ + { + "q": { + "_id": 1 + }, + "u": { + "_id": 1, + "a": { + "$b": 1 + } + }, + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "a": { + "$b": 1 + } + } + ] + } + ] + }, + { + "description": "Replacing document with dollar-prefixed key in embedded doc on pre-5.0 server yields server-side error", + "runOnRequirements": [ + { + "maxServerVersion": "4.99" + } + ], + "operations": [ + { + "name": "replaceOne", + "object": "collection0", + "arguments": { + "filter": { + "_id": 1 + }, + "replacement": { + "_id": 1, + "a": { + "$b": 1 + } + } + }, + "expectError": { + "isClientError": false + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "update": "coll0", + "updates": [ + { + "q": { + "_id": 1 + }, + "u": { + "_id": 1, + "a": { + "$b": 1 + } + }, + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1 + } + ] + } + ] + }, + { + "description": "Replacing document with dotted key in embedded doc on 3.6+ server", + "runOnRequirements": [ + { + "minServerVersion": "3.6" + } + ], + "operations": [ + { + "name": "replaceOne", + "object": "collection0", + "arguments": { + "filter": { + "_id": 1 + }, + "replacement": { + "_id": 1, + "a": { + "b.c": 1 + } + } + }, + "expectResult": { + "matchedCount": 1, + "modifiedCount": 1, + "upsertedCount": 0 + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "update": "coll0", + "updates": [ + { + "q": { + "_id": 1 + }, + "u": { + "_id": 1, + "a": { + "b.c": 1 + } + }, + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "a": { + "b.c": 1 + } + } + ] + } + ] + }, + { + "description": "Replacing document with dotted key in embedded doc on pre-3.6 server yields server-side error", + "runOnRequirements": [ + { + "maxServerVersion": "3.4.99" + } + ], + "operations": [ + { + "name": "replaceOne", + "object": "collection0", + "arguments": { + "filter": { + "_id": 1 + }, + "replacement": { + "_id": 1, + "a": { + "b.c": 1 + } + } + }, + "expectError": { + "isClientError": false + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "update": "coll0", + "updates": [ + { + "q": { + "_id": 1 + }, + "u": { + "_id": 1, + "a": { + "b.c": 1 + } + }, + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1 + } + ] + } + ] + }, + { + "description": "Unacknowledged write using dollar-prefixed or dotted keys may be silently rejected on pre-5.0 server", + "runOnRequirements": [ + { + "maxServerVersion": "4.99" + } + ], + "operations": [ + { + "name": "replaceOne", + "object": "collection1", + "arguments": { + "filter": { + "_id": 1 + }, + "replacement": { + "_id": 1, + "a": { + "$b": 1 + } + } + }, + "expectResult": { + "acknowledged": { + "$$unsetOrMatches": false + } + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "update": "coll1", + "updates": [ + { + "q": { + "_id": 1 + }, + "u": { + "_id": 1, + "a": { + "$b": 1 + } + }, + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false + } + } + ], + "writeConcern": { + "w": 0 + } + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1 + } + ] + } + ] + } + ] +} diff --git a/test/spec/crud/unified/replaceOne-dots_and_dollars.yml b/test/spec/crud/unified/replaceOne-dots_and_dollars.yml new file mode 100644 index 00000000000..b834e222055 --- /dev/null +++ b/test/spec/crud/unified/replaceOne-dots_and_dollars.yml @@ -0,0 +1,180 @@ +description: "replaceOne-dots_and_dollars" + +schemaVersion: "1.0" + +createEntities: + - client: + id: &client0 client0 + observeEvents: [ commandStartedEvent ] + - database: + id: &database0 database0 + client: *client0 + databaseName: &database0Name crud-tests + - collection: + id: &collection0 collection0 + database: *database0 + collectionName: &collection0Name coll0 + - collection: + id: &collection1 collection1 + database: *database0 + collectionName: &collection1Name coll1 + collectionOptions: + writeConcern: { w: 0 } + +initialData: &initialData + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - { _id: 1 } + +tests: + - description: "Replacing document with top-level dotted key on 3.6+ server" + runOnRequirements: + - minServerVersion: "3.6" + operations: + - name: replaceOne + object: *collection0 + arguments: + filter: { _id: 1 } + replacement: &dottedKey { _id: 1, a.b: 1 } + expectResult: &replaceResult + matchedCount: 1 + modifiedCount: 1 + upsertedCount: 0 + expectEvents: &expectEventsDottedKey + - client: *client0 + events: + - commandStartedEvent: + command: + update: *collection0Name + updates: + - q: { _id: 1 } + u: *dottedKey + multi: { $$unsetOrMatches: false } + upsert: { $$unsetOrMatches: false } + outcome: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - *dottedKey + + - description: "Replacing document with top-level dotted key on pre-3.6 server yields server-side error" + runOnRequirements: + - maxServerVersion: "3.4.99" + operations: + - name: replaceOne + object: *collection0 + arguments: + filter: { _id: 1 } + replacement: *dottedKey + expectError: + isClientError: false + expectEvents: *expectEventsDottedKey + outcome: *initialData + + - description: "Replacing document with dollar-prefixed key in embedded doc on 5.0+ server" + runOnRequirements: + - minServerVersion: "5.0" + operations: + - name: replaceOne + object: *collection0 + arguments: + filter: { _id: 1 } + replacement: &dollarPrefixedKeyInEmbedded { _id: 1, a: { $b: 1 } } + expectResult: *replaceResult + expectEvents: &expectEventsDollarPrefixedKeyInEmbedded + - client: *client0 + events: + - commandStartedEvent: + command: + update: *collection0Name + updates: + - q: { _id: 1 } + u: *dollarPrefixedKeyInEmbedded + multi: { $$unsetOrMatches: false } + upsert: { $$unsetOrMatches: false } + outcome: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - *dollarPrefixedKeyInEmbedded + + - description: "Replacing document with dollar-prefixed key in embedded doc on pre-5.0 server yields server-side error" + runOnRequirements: + - maxServerVersion: "4.99" + operations: + - name: replaceOne + object: *collection0 + arguments: + filter: { _id: 1 } + replacement: *dollarPrefixedKeyInEmbedded + expectError: + isClientError: false + expectEvents: *expectEventsDollarPrefixedKeyInEmbedded + outcome: *initialData + + - description: "Replacing document with dotted key in embedded doc on 3.6+ server" + runOnRequirements: + - minServerVersion: "3.6" + operations: + - name: replaceOne + object: *collection0 + arguments: + filter: { _id: 1 } + replacement: &dottedKeyInEmbedded { _id: 1, a: { b.c: 1 } } + expectResult: *replaceResult + expectEvents: &expectEventsDottedKeyInEmbedded + - client: *client0 + events: + - commandStartedEvent: + command: + update: *collection0Name + updates: + - q: { _id: 1 } + u: *dottedKeyInEmbedded + multi: { $$unsetOrMatches: false } + upsert: { $$unsetOrMatches: false } + outcome: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - *dottedKeyInEmbedded + + - description: "Replacing document with dotted key in embedded doc on pre-3.6 server yields server-side error" + runOnRequirements: + - maxServerVersion: "3.4.99" + operations: + - name: replaceOne + object: *collection0 + arguments: + filter: { _id: 1 } + replacement: *dottedKeyInEmbedded + expectError: + isClientError: false + expectEvents: *expectEventsDottedKeyInEmbedded + outcome: *initialData + + - description: "Unacknowledged write using dollar-prefixed or dotted keys may be silently rejected on pre-5.0 server" + runOnRequirements: + - maxServerVersion: "4.99" + operations: + - name: replaceOne + object: *collection1 + arguments: + filter: { _id: 1 } + replacement: *dollarPrefixedKeyInEmbedded + expectResult: + acknowledged: { $$unsetOrMatches: false } + expectEvents: + - client: *client0 + events: + - commandStartedEvent: + command: + update: *collection1Name + updates: + - q: { _id: 1 } + u: *dollarPrefixedKeyInEmbedded + multi: { $$unsetOrMatches: false } + upsert: { $$unsetOrMatches: false } + writeConcern: { w: 0 } + outcome: *initialData diff --git a/test/spec/crud/unified/updateMany-dots_and_dollars.json b/test/spec/crud/unified/updateMany-dots_and_dollars.json new file mode 100644 index 00000000000..5d3b9d0453a --- /dev/null +++ b/test/spec/crud/unified/updateMany-dots_and_dollars.json @@ -0,0 +1,404 @@ +{ + "description": "updateMany-dots_and_dollars", + "schemaVersion": "1.0", + "createEntities": [ + { + "client": { + "id": "client0", + "observeEvents": [ + "commandStartedEvent" + ] + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "crud-tests" + } + }, + { + "collection": { + "id": "collection0", + "database": "database0", + "collectionName": "coll0" + } + } + ], + "initialData": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "foo": {} + } + ] + } + ], + "tests": [ + { + "description": "Updating document to set top-level dollar-prefixed key on 5.0+ server", + "runOnRequirements": [ + { + "minServerVersion": "5.0" + } + ], + "operations": [ + { + "name": "updateMany", + "object": "collection0", + "arguments": { + "filter": { + "_id": 1 + }, + "update": [ + { + "$replaceWith": { + "$setField": { + "field": { + "$literal": "$a" + }, + "value": 1, + "input": "$$ROOT" + } + } + } + ] + }, + "expectResult": { + "matchedCount": 1, + "modifiedCount": 1, + "upsertedCount": 0 + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "update": "coll0", + "updates": [ + { + "q": { + "_id": 1 + }, + "u": [ + { + "$replaceWith": { + "$setField": { + "field": { + "$literal": "$a" + }, + "value": 1, + "input": "$$ROOT" + } + } + } + ], + "multi": true, + "upsert": { + "$$unsetOrMatches": false + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "foo": {}, + "$a": 1 + } + ] + } + ] + }, + { + "description": "Updating document to set top-level dotted key on 5.0+ server", + "runOnRequirements": [ + { + "minServerVersion": "5.0" + } + ], + "operations": [ + { + "name": "updateMany", + "object": "collection0", + "arguments": { + "filter": { + "_id": 1 + }, + "update": [ + { + "$replaceWith": { + "$setField": { + "field": { + "$literal": "a.b" + }, + "value": 1, + "input": "$$ROOT" + } + } + } + ] + }, + "expectResult": { + "matchedCount": 1, + "modifiedCount": 1, + "upsertedCount": 0 + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "update": "coll0", + "updates": [ + { + "q": { + "_id": 1 + }, + "u": [ + { + "$replaceWith": { + "$setField": { + "field": { + "$literal": "a.b" + }, + "value": 1, + "input": "$$ROOT" + } + } + } + ], + "multi": true, + "upsert": { + "$$unsetOrMatches": false + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "foo": {}, + "a.b": 1 + } + ] + } + ] + }, + { + "description": "Updating document to set dollar-prefixed key in embedded doc on 5.0+ server", + "runOnRequirements": [ + { + "minServerVersion": "5.0" + } + ], + "operations": [ + { + "name": "updateMany", + "object": "collection0", + "arguments": { + "filter": { + "_id": 1 + }, + "update": [ + { + "$set": { + "foo": { + "$setField": { + "field": { + "$literal": "$a" + }, + "value": 1, + "input": "$foo" + } + } + } + } + ] + }, + "expectResult": { + "matchedCount": 1, + "modifiedCount": 1, + "upsertedCount": 0 + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "update": "coll0", + "updates": [ + { + "q": { + "_id": 1 + }, + "u": [ + { + "$set": { + "foo": { + "$setField": { + "field": { + "$literal": "$a" + }, + "value": 1, + "input": "$foo" + } + } + } + } + ], + "multi": true, + "upsert": { + "$$unsetOrMatches": false + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "foo": { + "$a": 1 + } + } + ] + } + ] + }, + { + "description": "Updating document to set dotted key in embedded doc on 5.0+ server", + "runOnRequirements": [ + { + "minServerVersion": "5.0" + } + ], + "operations": [ + { + "name": "updateMany", + "object": "collection0", + "arguments": { + "filter": { + "_id": 1 + }, + "update": [ + { + "$set": { + "foo": { + "$setField": { + "field": { + "$literal": "a.b" + }, + "value": 1, + "input": "$foo" + } + } + } + } + ] + }, + "expectResult": { + "matchedCount": 1, + "modifiedCount": 1, + "upsertedCount": 0 + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "update": "coll0", + "updates": [ + { + "q": { + "_id": 1 + }, + "u": [ + { + "$set": { + "foo": { + "$setField": { + "field": { + "$literal": "a.b" + }, + "value": 1, + "input": "$foo" + } + } + } + } + ], + "multi": true, + "upsert": { + "$$unsetOrMatches": false + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "foo": { + "a.b": 1 + } + } + ] + } + ] + } + ] +} diff --git a/test/spec/crud/unified/updateMany-dots_and_dollars.yml b/test/spec/crud/unified/updateMany-dots_and_dollars.yml new file mode 100644 index 00000000000..6c9da82a5ad --- /dev/null +++ b/test/spec/crud/unified/updateMany-dots_and_dollars.yml @@ -0,0 +1,138 @@ +description: "updateMany-dots_and_dollars" + +schemaVersion: "1.0" + +createEntities: + - client: + id: &client0 client0 + observeEvents: [ commandStartedEvent ] + - database: + id: &database0 database0 + client: *client0 + databaseName: &database0Name crud-tests + - collection: + id: &collection0 collection0 + database: *database0 + collectionName: &collection0Name coll0 + +initialData: &initialData + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - { _id: 1, foo: {} } + +tests: + - description: "Updating document to set top-level dollar-prefixed key on 5.0+ server" + runOnRequirements: + - minServerVersion: "5.0" + operations: + - name: updateMany + object: *collection0 + arguments: + filter: { _id: 1 } + update: &dollarPrefixedKey + - { $replaceWith: { $setField: { field: { $literal: $a }, value: 1, input: $$ROOT } } } + expectResult: &updateResult + matchedCount: 1 + modifiedCount: 1 + upsertedCount: 0 + expectEvents: + - client: *client0 + events: + - commandStartedEvent: + command: + update: *collection0Name + updates: + - q: { _id: 1 } + u: *dollarPrefixedKey + multi: true + upsert: { $$unsetOrMatches: false } + outcome: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - { _id: 1, foo: {}, $a: 1 } + + - description: "Updating document to set top-level dotted key on 5.0+ server" + runOnRequirements: + - minServerVersion: "5.0" + operations: + - name: updateMany + object: *collection0 + arguments: + filter: { _id: 1 } + update: &dottedKey + - { $replaceWith: { $setField: { field: { $literal: a.b }, value: 1, input: $$ROOT } } } + expectResult: *updateResult + expectEvents: + - client: *client0 + events: + - commandStartedEvent: + command: + update: *collection0Name + updates: + - q: { _id: 1 } + u: *dottedKey + multi: true + upsert: { $$unsetOrMatches: false } + outcome: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - { _id: 1, foo: {}, a.b: 1 } + + - description: "Updating document to set dollar-prefixed key in embedded doc on 5.0+ server" + runOnRequirements: + - minServerVersion: "5.0" + operations: + - name: updateMany + object: *collection0 + arguments: + filter: { _id: 1 } + update: &dollarPrefixedKeyInEmbedded + - { $set: { foo: { $setField: { field: { $literal: $a }, value: 1, input: $foo } } } } + expectResult: *updateResult + expectEvents: + - client: *client0 + events: + - commandStartedEvent: + command: + update: *collection0Name + updates: + - q: { _id: 1 } + u: *dollarPrefixedKeyInEmbedded + multi: true + upsert: { $$unsetOrMatches: false } + outcome: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - { _id: 1, foo: { $a: 1 } } + + - description: "Updating document to set dotted key in embedded doc on 5.0+ server" + runOnRequirements: + - minServerVersion: "5.0" + operations: + - name: updateMany + object: *collection0 + arguments: + filter: { _id: 1 } + update: &dottedKeyInEmbedded + - { $set: { foo: { $setField: { field: { $literal: a.b }, value: 1, input: $foo } } } } + expectResult: *updateResult + expectEvents: + - client: *client0 + events: + - commandStartedEvent: + command: + update: *collection0Name + updates: + - q: { _id: 1 } + u: *dottedKeyInEmbedded + multi: true + upsert: { $$unsetOrMatches: false } + outcome: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - { _id: 1, foo: { a.b: 1 } } diff --git a/test/spec/crud/unified/updateOne-dots_and_dollars.json b/test/spec/crud/unified/updateOne-dots_and_dollars.json new file mode 100644 index 00000000000..798d522cba3 --- /dev/null +++ b/test/spec/crud/unified/updateOne-dots_and_dollars.json @@ -0,0 +1,412 @@ +{ + "description": "updateOne-dots_and_dollars", + "schemaVersion": "1.0", + "createEntities": [ + { + "client": { + "id": "client0", + "observeEvents": [ + "commandStartedEvent" + ] + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "crud-tests" + } + }, + { + "collection": { + "id": "collection0", + "database": "database0", + "collectionName": "coll0" + } + } + ], + "initialData": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "foo": {} + } + ] + } + ], + "tests": [ + { + "description": "Updating document to set top-level dollar-prefixed key on 5.0+ server", + "runOnRequirements": [ + { + "minServerVersion": "5.0" + } + ], + "operations": [ + { + "name": "updateOne", + "object": "collection0", + "arguments": { + "filter": { + "_id": 1 + }, + "update": [ + { + "$replaceWith": { + "$setField": { + "field": { + "$literal": "$a" + }, + "value": 1, + "input": "$$ROOT" + } + } + } + ] + }, + "expectResult": { + "matchedCount": 1, + "modifiedCount": 1, + "upsertedCount": 0 + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "update": "coll0", + "updates": [ + { + "q": { + "_id": 1 + }, + "u": [ + { + "$replaceWith": { + "$setField": { + "field": { + "$literal": "$a" + }, + "value": 1, + "input": "$$ROOT" + } + } + } + ], + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "foo": {}, + "$a": 1 + } + ] + } + ] + }, + { + "description": "Updating document to set top-level dotted key on 5.0+ server", + "runOnRequirements": [ + { + "minServerVersion": "5.0" + } + ], + "operations": [ + { + "name": "updateOne", + "object": "collection0", + "arguments": { + "filter": { + "_id": 1 + }, + "update": [ + { + "$replaceWith": { + "$setField": { + "field": { + "$literal": "a.b" + }, + "value": 1, + "input": "$$ROOT" + } + } + } + ] + }, + "expectResult": { + "matchedCount": 1, + "modifiedCount": 1, + "upsertedCount": 0 + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "update": "coll0", + "updates": [ + { + "q": { + "_id": 1 + }, + "u": [ + { + "$replaceWith": { + "$setField": { + "field": { + "$literal": "a.b" + }, + "value": 1, + "input": "$$ROOT" + } + } + } + ], + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "foo": {}, + "a.b": 1 + } + ] + } + ] + }, + { + "description": "Updating document to set dollar-prefixed key in embedded doc on 5.0+ server", + "runOnRequirements": [ + { + "minServerVersion": "5.0" + } + ], + "operations": [ + { + "name": "updateOne", + "object": "collection0", + "arguments": { + "filter": { + "_id": 1 + }, + "update": [ + { + "$set": { + "foo": { + "$setField": { + "field": { + "$literal": "$a" + }, + "value": 1, + "input": "$foo" + } + } + } + } + ] + }, + "expectResult": { + "matchedCount": 1, + "modifiedCount": 1, + "upsertedCount": 0 + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "update": "coll0", + "updates": [ + { + "q": { + "_id": 1 + }, + "u": [ + { + "$set": { + "foo": { + "$setField": { + "field": { + "$literal": "$a" + }, + "value": 1, + "input": "$foo" + } + } + } + } + ], + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "foo": { + "$a": 1 + } + } + ] + } + ] + }, + { + "description": "Updating document to set dotted key in embedded doc on 5.0+ server", + "runOnRequirements": [ + { + "minServerVersion": "5.0" + } + ], + "operations": [ + { + "name": "updateOne", + "object": "collection0", + "arguments": { + "filter": { + "_id": 1 + }, + "update": [ + { + "$set": { + "foo": { + "$setField": { + "field": { + "$literal": "a.b" + }, + "value": 1, + "input": "$foo" + } + } + } + } + ] + }, + "expectResult": { + "matchedCount": 1, + "modifiedCount": 1, + "upsertedCount": 0 + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "update": "coll0", + "updates": [ + { + "q": { + "_id": 1 + }, + "u": [ + { + "$set": { + "foo": { + "$setField": { + "field": { + "$literal": "a.b" + }, + "value": 1, + "input": "$foo" + } + } + } + } + ], + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "foo": { + "a.b": 1 + } + } + ] + } + ] + } + ] +} diff --git a/test/spec/crud/unified/updateOne-dots_and_dollars.yml b/test/spec/crud/unified/updateOne-dots_and_dollars.yml new file mode 100644 index 00000000000..9ff8a38d736 --- /dev/null +++ b/test/spec/crud/unified/updateOne-dots_and_dollars.yml @@ -0,0 +1,138 @@ +description: "updateOne-dots_and_dollars" + +schemaVersion: "1.0" + +createEntities: + - client: + id: &client0 client0 + observeEvents: [ commandStartedEvent ] + - database: + id: &database0 database0 + client: *client0 + databaseName: &database0Name crud-tests + - collection: + id: &collection0 collection0 + database: *database0 + collectionName: &collection0Name coll0 + +initialData: &initialData + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - { _id: 1, foo: {} } + +tests: + - description: "Updating document to set top-level dollar-prefixed key on 5.0+ server" + runOnRequirements: + - minServerVersion: "5.0" + operations: + - name: updateOne + object: *collection0 + arguments: + filter: { _id: 1 } + update: &dollarPrefixedKey + - { $replaceWith: { $setField: { field: { $literal: $a }, value: 1, input: $$ROOT } } } + expectResult: &updateResult + matchedCount: 1 + modifiedCount: 1 + upsertedCount: 0 + expectEvents: + - client: *client0 + events: + - commandStartedEvent: + command: + update: *collection0Name + updates: + - q: { _id: 1 } + u: *dollarPrefixedKey + multi: { $$unsetOrMatches: false } + upsert: { $$unsetOrMatches: false } + outcome: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - { _id: 1, foo: {}, $a: 1 } + + - description: "Updating document to set top-level dotted key on 5.0+ server" + runOnRequirements: + - minServerVersion: "5.0" + operations: + - name: updateOne + object: *collection0 + arguments: + filter: { _id: 1 } + update: &dottedKey + - { $replaceWith: { $setField: { field: { $literal: a.b }, value: 1, input: $$ROOT } } } + expectResult: *updateResult + expectEvents: + - client: *client0 + events: + - commandStartedEvent: + command: + update: *collection0Name + updates: + - q: { _id: 1 } + u: *dottedKey + multi: { $$unsetOrMatches: false } + upsert: { $$unsetOrMatches: false } + outcome: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - { _id: 1, foo: {}, a.b: 1 } + + - description: "Updating document to set dollar-prefixed key in embedded doc on 5.0+ server" + runOnRequirements: + - minServerVersion: "5.0" + operations: + - name: updateOne + object: *collection0 + arguments: + filter: { _id: 1 } + update: &dollarPrefixedKeyInEmbedded + - { $set: { foo: { $setField: { field: { $literal: $a }, value: 1, input: $foo } } } } + expectResult: *updateResult + expectEvents: + - client: *client0 + events: + - commandStartedEvent: + command: + update: *collection0Name + updates: + - q: { _id: 1 } + u: *dollarPrefixedKeyInEmbedded + multi: { $$unsetOrMatches: false } + upsert: { $$unsetOrMatches: false } + outcome: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - { _id: 1, foo: { $a: 1 } } + + - description: "Updating document to set dotted key in embedded doc on 5.0+ server" + runOnRequirements: + - minServerVersion: "5.0" + operations: + - name: updateOne + object: *collection0 + arguments: + filter: { _id: 1 } + update: &dottedKeyInEmbedded + - { $set: { foo: { $setField: { field: { $literal: a.b }, value: 1, input: $foo } } } } + expectResult: *updateResult + expectEvents: + - client: *client0 + events: + - commandStartedEvent: + command: + update: *collection0Name + updates: + - q: { _id: 1 } + u: *dottedKeyInEmbedded + multi: { $$unsetOrMatches: false } + upsert: { $$unsetOrMatches: false } + outcome: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - { _id: 1, foo: { a.b: 1 } } diff --git a/test/spec/transactions/legacy/errors-client.json b/test/spec/transactions/legacy/errors-client.json index 4bd1c0eb321..15fae96fecf 100644 --- a/test/spec/transactions/legacy/errors-client.json +++ b/test/spec/transactions/legacy/errors-client.json @@ -25,14 +25,15 @@ "object": "session0" }, { - "name": "insertOne", + "name": "updateOne", "object": "collection", "arguments": { "session": "session0", - "document": { - "_id": { - ".": "." - } + "filter": { + "_id": 1 + }, + "update": { + "x": 1 } }, "error": true @@ -60,22 +61,23 @@ "arguments": { "session": "session0", "document": { - "_id": 4 + "_id": 1 } }, "result": { - "insertedId": 4 + "insertedId": 1 } }, { - "name": "insertOne", + "name": "updateOne", "object": "collection", "arguments": { "session": "session0", - "document": { - "_id": { - ".": "." - } + "filter": { + "_id": 1 + }, + "update": { + "x": 1 } }, "error": true diff --git a/test/spec/transactions/legacy/errors-client.yml b/test/spec/transactions/legacy/errors-client.yml index 153b130942b..38b110424d1 100644 --- a/test/spec/transactions/legacy/errors-client.yml +++ b/test/spec/transactions/legacy/errors-client.yml @@ -16,12 +16,12 @@ tests: operations: - name: startTransaction object: session0 - - name: insertOne + - name: updateOne object: collection arguments: session: session0 - document: - _id: {.: .} + filter: { _id: 1 } + update: { x: 1 } error: true - name: assertSessionTransactionState object: testRunner @@ -38,16 +38,15 @@ tests: object: collection arguments: session: session0 - document: - _id: 4 + document: { _id: 1 } result: - insertedId: 4 - - name: insertOne + insertedId: 1 + - name: updateOne object: collection arguments: session: session0 - document: - _id: {.: .} + filter: { _id: 1 } + update: { x: 1 } error: true - name: assertSessionTransactionState object: testRunner diff --git a/test/spec/unified-test-format/valid-pass/poc-transactions.json b/test/spec/unified-test-format/valid-pass/poc-transactions.json index 62528f9ce1a..0355ca20605 100644 --- a/test/spec/unified-test-format/valid-pass/poc-transactions.json +++ b/test/spec/unified-test-format/valid-pass/poc-transactions.json @@ -61,14 +61,15 @@ "object": "session0" }, { - "name": "insertOne", + "name": "updateOne", "object": "collection0", "arguments": { "session": "session0", - "document": { - "_id": { - ".": "." - } + "filter": { + "_id": 1 + }, + "update": { + "x": 1 } }, "expectError": { diff --git a/test/spec/unified-test-format/valid-pass/poc-transactions.yml b/test/spec/unified-test-format/valid-pass/poc-transactions.yml index 5f229e464c9..0a66b9bd7f6 100644 --- a/test/spec/unified-test-format/valid-pass/poc-transactions.yml +++ b/test/spec/unified-test-format/valid-pass/poc-transactions.yml @@ -34,11 +34,12 @@ tests: operations: - name: startTransaction object: *session0 - - name: insertOne + - name: updateOne object: *collection0 arguments: session: *session0 - document: { _id: { .: . } } + filter: { _id: 1 } + update: { x: 1 } # Original test only asserted a generic error expectError: { isClientError: true } - name: assertSessionTransactionState