From 2c4e59f40b626b6080361830d855a7824511f352 Mon Sep 17 00:00:00 2001 From: Qingyang Hu Date: Fri, 30 Aug 2024 16:00:09 -0400 Subject: [PATCH 01/10] DRIVERS-2822 Add sort option to `updateOne` --- source/crud/crud.md | 26 +- .../unified/bulkWrite-updateOne-sort.json | 256 ++++++++++++++++++ .../unified/bulkWrite-updateOne-sort.yml | 125 +++++++++ .../crud/tests/unified/updateMany-sort.json | 225 +++++++++++++++ source/crud/tests/unified/updateMany-sort.yml | 117 ++++++++ source/crud/tests/unified/updateOne-sort.json | 241 +++++++++++++++++ source/crud/tests/unified/updateOne-sort.yml | 125 +++++++++ 7 files changed, 1114 insertions(+), 1 deletion(-) create mode 100644 source/crud/tests/unified/bulkWrite-updateOne-sort.json create mode 100644 source/crud/tests/unified/bulkWrite-updateOne-sort.yml create mode 100644 source/crud/tests/unified/updateMany-sort.json create mode 100644 source/crud/tests/unified/updateMany-sort.yml create mode 100644 source/crud/tests/unified/updateOne-sort.json create mode 100644 source/crud/tests/unified/updateOne-sort.yml diff --git a/source/crud/crud.md b/source/crud/crud.md index ea96efec9a..30668c9580 100644 --- a/source/crud/crud.md +++ b/source/crud/crud.md @@ -1048,7 +1048,6 @@ class UpdateOptions { */ upsert: Optional; - /** * Map of parameter names and values. Values must be constant or closed * expressions that do not reference document fields. Parameters can then be @@ -1070,6 +1069,18 @@ class UpdateOptions { * and providing one will result in a server-side error. */ comment: Optional; + + /** + * Specify which document the operation updates if the query matches multiple + * documents. The first document matched by the sort order will be updated. + * + * This option is sent only if the caller explicitly provides a value. The default is to not send a value. + * This option is only supported by servers >= 8.0. Older servers will report an error for using this option. + * The driver MUST raise an error if the caller explicitly provides a value with updateMany(). + * + * @see https://www.mongodb.com/docs/manual/reference/command/update/ + */ + sort: Optional; } class ReplaceOptions { @@ -1380,6 +1391,17 @@ class UpdateOneModel implements WriteModel { */ hint: Optional<(String | Document)>; + /** + * Specify which document the operation updates if the query matches multiple + * documents. The first document matched by the sort order will be updated. + * + * This option is sent only if the caller explicitly provides a value. The default is to not send a value. + * This option is only supported by servers >= 8.0. Older servers will report an error for using this option. + * + * @see https://www.mongodb.com/docs/manual/reference/command/update/ + */ + sort: Optional; + /** * When true, creates a new document if no document matches the query. * @@ -2369,6 +2391,8 @@ aforementioned allowance in the SemVer spec. ## Changelog +- 2024-08-30: Add sort option to `updateOne`. + - 2024-02-20: Migrated from reStructuredText to Markdown. - 2022-10-05: Remove spec front matter and reformat changelog. diff --git a/source/crud/tests/unified/bulkWrite-updateOne-sort.json b/source/crud/tests/unified/bulkWrite-updateOne-sort.json new file mode 100644 index 0000000000..4ea4f26665 --- /dev/null +++ b/source/crud/tests/unified/bulkWrite-updateOne-sort.json @@ -0,0 +1,256 @@ +{ + "description": "BulkWrite updateOne-sort", + "schemaVersion": "1.0", + "createEntities": [ + { + "client": { + "id": "client0", + "observeEvents": [ + "commandStartedEvent", + "commandSucceededEvent" + ] + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "crud-tests" + } + }, + { + "collection": { + "id": "collection0", + "database": "database0", + "collectionName": "coll0" + } + } + ], + "initialData": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + } + ] + } + ], + "tests": [ + { + "description": "BulkWrite updateOne with sort option", + "runOnRequirements": [ + { + "minServerVersion": "8.0" + } + ], + "operations": [ + { + "object": "collection0", + "name": "bulkWrite", + "arguments": { + "requests": [ + { + "updateOne": { + "filter": { + "_id": { + "$gt": 1 + } + }, + "sort": { + "_id": -1 + }, + "update": [ + { + "$set": { + "x": 1 + } + } + ] + } + } + ] + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "update": "coll0", + "updates": [ + { + "q": { + "_id": { + "$gt": 1 + } + }, + "u": [ + { + "$set": { + "x": 1 + } + } + ], + "sort": { + "_id": -1 + }, + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false + } + } + ] + } + } + }, + { + "commandSucceededEvent": { + "reply": { + "ok": 1, + "n": 1 + }, + "commandName": "update" + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 1 + } + ] + } + ] + }, + { + "description": "BulkWrite updateOne with sort option unsupported (server-side error)", + "runOnRequirements": [ + { + "maxServerVersion": "7.99" + } + ], + "operations": [ + { + "object": "collection0", + "name": "bulkWrite", + "arguments": { + "requests": [ + { + "updateOne": { + "filter": { + "_id": { + "$gt": 1 + } + }, + "sort": { + "_id": -1 + }, + "update": [ + { + "$set": { + "x": 1 + } + } + ] + } + } + ] + }, + "expectError": { + "errorContains": "'update.updates.sort' is an unknown field", + "isClientError": false + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "update": "coll0", + "updates": [ + { + "q": { + "_id": { + "$gt": 1 + } + }, + "u": [ + { + "$set": { + "x": 1 + } + } + ], + "sort": { + "_id": -1 + }, + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + } + ] + } + ] + } + ] +} diff --git a/source/crud/tests/unified/bulkWrite-updateOne-sort.yml b/source/crud/tests/unified/bulkWrite-updateOne-sort.yml new file mode 100644 index 0000000000..91fd201c8c --- /dev/null +++ b/source/crud/tests/unified/bulkWrite-updateOne-sort.yml @@ -0,0 +1,125 @@ +description: BulkWrite updateOne-sort +schemaVersion: "1.0" +createEntities: + - client: + id: client0 + observeEvents: + - commandStartedEvent + - commandSucceededEvent + - database: + id: database0 + client: client0 + databaseName: crud-tests + - collection: + id: collection0 + database: database0 + collectionName: coll0 +initialData: + - collectionName: coll0 + databaseName: crud-tests + documents: + - _id: 1 + x: 11 + - _id: 2 + x: 22 + - _id: 3 + x: 33 +tests: + - description: BulkWrite updateOne with sort option + runOnRequirements: + - minServerVersion: "8.0" + operations: + - object: collection0 + name: bulkWrite + arguments: + requests: + - updateOne: + filter: + _id: + $gt: 1 + sort: + _id: -1 + update: + - $set: + x: 1 + expectEvents: + - client: client0 + events: + - commandStartedEvent: + command: + update: coll0 + updates: + - q: + _id: + $gt: 1 + u: + - $set: + x: 1 + sort: + _id: -1 + multi: + $$unsetOrMatches: false + upsert: + $$unsetOrMatches: false + - commandSucceededEvent: + reply: { ok: 1, n: 1 } + commandName: update + outcome: + - collectionName: coll0 + databaseName: crud-tests + documents: + - _id: 1 + x: 11 + - _id: 2 + x: 22 + - _id: 3 + x: 1 + - description: BulkWrite updateOne with sort option unsupported (server-side error) + runOnRequirements: + - maxServerVersion: "7.99" + operations: + - object: collection0 + name: bulkWrite + arguments: + requests: + - updateOne: + filter: + _id: + $gt: 1 + sort: + _id: -1 + update: + - $set: + x: 1 + expectError: + errorContains: "'update.updates.sort' is an unknown field" + isClientError: false + expectEvents: + - client: client0 + events: + - commandStartedEvent: + command: + update: coll0 + updates: + - q: + _id: + $gt: 1 + u: + - $set: + x: 1 + sort: + _id: -1 + multi: + $$unsetOrMatches: false + upsert: + $$unsetOrMatches: false + outcome: + - collectionName: coll0 + databaseName: crud-tests + documents: + - _id: 1 + x: 11 + - _id: 2 + x: 22 + - _id: 3 + x: 33 diff --git a/source/crud/tests/unified/updateMany-sort.json b/source/crud/tests/unified/updateMany-sort.json new file mode 100644 index 0000000000..4cf1f05c63 --- /dev/null +++ b/source/crud/tests/unified/updateMany-sort.json @@ -0,0 +1,225 @@ +{ + "description": "updateMany-sort", + "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, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + } + ] + } + ], + "tests": [ + { + "description": "UpdateMany with sort option unsupported", + "runOnRequirements": [ + { + "minServerVersion": "8.0" + } + ], + "operations": [ + { + "name": "updateMany", + "object": "collection0", + "arguments": { + "filter": { + "_id": { + "$gt": 1 + } + }, + "sort": { + "_id": -1 + }, + "update": { + "$inc": { + "x": 1 + } + } + }, + "expectError": { + "isError": true + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "update": "coll0", + "updates": [ + { + "q": { + "_id": { + "$gt": 1 + } + }, + "u": { + "$inc": { + "x": 1 + } + }, + "sort": { + "_id": -1 + }, + "multi": true, + "upsert": { + "$$unsetOrMatches": false + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + } + ] + } + ] + }, + { + "description": "updateMany with sort option unsupported (server-side error)", + "runOnRequirements": [ + { + "maxServerVersion": "7.99" + } + ], + "operations": [ + { + "name": "updateMany", + "object": "collection0", + "arguments": { + "filter": { + "_id": { + "$gt": 1 + } + }, + "sort": { + "_id": -1 + }, + "update": { + "$inc": { + "x": 1 + } + } + }, + "expectError": { + "errorContains": "'update.updates.sort' is an unknown field", + "isClientError": false + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "update": "coll0", + "updates": [ + { + "q": { + "_id": { + "$gt": 1 + } + }, + "u": { + "$inc": { + "x": 1 + } + }, + "sort": { + "_id": -1 + }, + "multi": true, + "upsert": { + "$$unsetOrMatches": false + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + } + ] + } + ] + } + ] +} diff --git a/source/crud/tests/unified/updateMany-sort.yml b/source/crud/tests/unified/updateMany-sort.yml new file mode 100644 index 0000000000..c2bda64e9b --- /dev/null +++ b/source/crud/tests/unified/updateMany-sort.yml @@ -0,0 +1,117 @@ +description: updateMany-sort +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 + x: 11 + - _id: 2 + x: 22 + - _id: 3 + x: 33 +tests: + - description: UpdateMany with sort option unsupported + runOnRequirements: + - minServerVersion: "8.0" + operations: + - name: updateMany + object: collection0 + arguments: + filter: + _id: + $gt: 1 + sort: + _id: -1 + update: + $inc: + x: 1 + expectError: + isError: true + expectEvents: + - client: client0 + events: + - commandStartedEvent: + command: + update: coll0 + updates: + - q: + _id: + $gt: 1 + u: + $inc: + x: 1 + sort: + _id: -1 + multi: true + upsert: + $$unsetOrMatches: false + outcome: + - collectionName: coll0 + databaseName: crud-tests + documents: + - _id: 1 + x: 11 + - _id: 2 + x: 22 + - _id: 3 + x: 33 + - description: updateMany with sort option unsupported (server-side error) + runOnRequirements: + - maxServerVersion: "7.99" + operations: + - name: updateMany + object: collection0 + arguments: + filter: + _id: + $gt: 1 + sort: + _id: -1 + update: + $inc: + x: 1 + expectError: + errorContains: "'update.updates.sort' is an unknown field" + isClientError: false + expectEvents: + - client: client0 + events: + - commandStartedEvent: + command: + update: coll0 + updates: + - q: + _id: + $gt: 1 + u: + $inc: + x: 1 + sort: + _id: -1 + multi: true + upsert: + $$unsetOrMatches: false + outcome: + - collectionName: coll0 + databaseName: crud-tests + documents: + - _id: 1 + x: 11 + - _id: 2 + x: 22 + - _id: 3 + x: 33 diff --git a/source/crud/tests/unified/updateOne-sort.json b/source/crud/tests/unified/updateOne-sort.json new file mode 100644 index 0000000000..9fe28f69f1 --- /dev/null +++ b/source/crud/tests/unified/updateOne-sort.json @@ -0,0 +1,241 @@ +{ + "description": "updateOne-sort", + "schemaVersion": "1.0", + "createEntities": [ + { + "client": { + "id": "client0", + "observeEvents": [ + "commandStartedEvent", + "commandSucceededEvent" + ] + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "crud-tests" + } + }, + { + "collection": { + "id": "collection0", + "database": "database0", + "collectionName": "coll0" + } + } + ], + "initialData": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + } + ] + } + ], + "tests": [ + { + "description": "UpdateOne with sort option", + "runOnRequirements": [ + { + "minServerVersion": "8.0" + } + ], + "operations": [ + { + "name": "updateOne", + "object": "collection0", + "arguments": { + "filter": { + "_id": { + "$gt": 1 + } + }, + "sort": { + "_id": -1 + }, + "update": { + "$inc": { + "x": 1 + } + } + }, + "expectResult": { + "matchedCount": 1, + "modifiedCount": 1, + "upsertedCount": 0 + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "update": "coll0", + "updates": [ + { + "q": { + "_id": { + "$gt": 1 + } + }, + "u": { + "$inc": { + "x": 1 + } + }, + "sort": { + "_id": -1 + }, + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false + } + } + ] + } + } + }, + { + "commandSucceededEvent": { + "reply": { + "ok": 1, + "n": 1 + }, + "commandName": "update" + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 34 + } + ] + } + ] + }, + { + "description": "updateOne with sort option unsupported (server-side error)", + "runOnRequirements": [ + { + "maxServerVersion": "7.99" + } + ], + "operations": [ + { + "name": "updateOne", + "object": "collection0", + "arguments": { + "filter": { + "_id": { + "$gt": 1 + } + }, + "sort": { + "_id": -1 + }, + "update": { + "$inc": { + "x": 1 + } + } + }, + "expectError": { + "errorContains": "'update.updates.sort' is an unknown field", + "isClientError": false + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "update": "coll0", + "updates": [ + { + "q": { + "_id": { + "$gt": 1 + } + }, + "u": { + "$inc": { + "x": 1 + } + }, + "sort": { + "_id": -1 + }, + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + } + ] + } + ] + } + ] +} diff --git a/source/crud/tests/unified/updateOne-sort.yml b/source/crud/tests/unified/updateOne-sort.yml new file mode 100644 index 0000000000..2354daa7ad --- /dev/null +++ b/source/crud/tests/unified/updateOne-sort.yml @@ -0,0 +1,125 @@ +description: updateOne-sort +schemaVersion: "1.0" +createEntities: + - client: + id: client0 + observeEvents: + - commandStartedEvent + - commandSucceededEvent + - database: + id: database0 + client: client0 + databaseName: crud-tests + - collection: + id: collection0 + database: database0 + collectionName: coll0 +initialData: + - collectionName: coll0 + databaseName: crud-tests + documents: + - _id: 1 + x: 11 + - _id: 2 + x: 22 + - _id: 3 + x: 33 +tests: + - description: UpdateOne with sort option + runOnRequirements: + - minServerVersion: "8.0" + operations: + - name: updateOne + object: collection0 + arguments: + filter: + _id: + $gt: 1 + sort: + _id: -1 + update: + $inc: + x: 1 + expectResult: + matchedCount: 1 + modifiedCount: 1 + upsertedCount: 0 + expectEvents: + - client: client0 + events: + - commandStartedEvent: + command: + update: coll0 + updates: + - q: + _id: + $gt: 1 + u: + $inc: + x: 1 + sort: + _id: -1 + multi: + $$unsetOrMatches: false + upsert: + $$unsetOrMatches: false + - commandSucceededEvent: + reply: { ok: 1, n: 1 } + commandName: update + outcome: + - collectionName: coll0 + databaseName: crud-tests + documents: + - _id: 1 + x: 11 + - _id: 2 + x: 22 + - _id: 3 + x: 34 + - description: updateOne with sort option unsupported (server-side error) + runOnRequirements: + - maxServerVersion: "7.99" + operations: + - name: updateOne + object: collection0 + arguments: + filter: + _id: + $gt: 1 + sort: + _id: -1 + update: + $inc: + x: 1 + expectError: + errorContains: "'update.updates.sort' is an unknown field" + isClientError: false + expectEvents: + - client: client0 + events: + - commandStartedEvent: + command: + update: coll0 + updates: + - q: + _id: + $gt: 1 + u: + $inc: + x: 1 + sort: + _id: -1 + multi: + $$unsetOrMatches: false + upsert: + $$unsetOrMatches: false + outcome: + - collectionName: coll0 + databaseName: crud-tests + documents: + - _id: 1 + x: 11 + - _id: 2 + x: 22 + - _id: 3 + x: 33 From fd31e710f91c51ef68383db62ad1bff126b1d0bc Mon Sep 17 00:00:00 2001 From: Qingyang Hu Date: Fri, 6 Sep 2024 09:59:38 -0400 Subject: [PATCH 02/10] Rely on the server to error updateMany; Add replaceOne tests. --- source/crud/crud.md | 26 +- .../unified/bulkWrite-replaceOne-sort.json | 239 ++++++++++++++++++ .../unified/bulkWrite-replaceOne-sort.yml | 94 +++++++ .../unified/bulkWrite-updateOne-sort.json | 1 - .../unified/bulkWrite-updateOne-sort.yml | 93 +++---- .../crud/tests/unified/replaceOne-sort.json | 232 +++++++++++++++++ source/crud/tests/unified/replaceOne-sort.yml | 94 +++++++ .../crud/tests/unified/updateMany-sort.json | 93 ------- source/crud/tests/unified/updateMany-sort.yml | 95 ++----- source/crud/tests/unified/updateOne-sort.json | 1 - source/crud/tests/unified/updateOne-sort.yml | 89 +++---- 11 files changed, 761 insertions(+), 296 deletions(-) create mode 100644 source/crud/tests/unified/bulkWrite-replaceOne-sort.json create mode 100644 source/crud/tests/unified/bulkWrite-replaceOne-sort.yml create mode 100644 source/crud/tests/unified/replaceOne-sort.json create mode 100644 source/crud/tests/unified/replaceOne-sort.yml diff --git a/source/crud/crud.md b/source/crud/crud.md index 30668c9580..cb50e9b493 100644 --- a/source/crud/crud.md +++ b/source/crud/crud.md @@ -1075,8 +1075,8 @@ class UpdateOptions { * documents. The first document matched by the sort order will be updated. * * This option is sent only if the caller explicitly provides a value. The default is to not send a value. + * The server will report an error if the caller explicitly provides a value with updateMany(). * This option is only supported by servers >= 8.0. Older servers will report an error for using this option. - * The driver MUST raise an error if the caller explicitly provides a value with updateMany(). * * @see https://www.mongodb.com/docs/manual/reference/command/update/ */ @@ -1149,6 +1149,17 @@ class ReplaceOptions { * and providing one will result in a server-side error. */ comment: Optional; + + /** + * Specify which document the operation replaces if the query matches multiple + * documents. The first document matched by the sort order will be replaced. + * + * This option is sent only if the caller explicitly provides a value. The default is to not send a value. + * This option is only supported by servers >= 8.0. Older servers will report an error for using this option. + * + * @see https://www.mongodb.com/docs/manual/reference/command/update/ + */ + sort: Optional; } class DeleteOptions { @@ -1329,6 +1340,17 @@ class ReplaceOneModel implements WriteModel { */ hint: Optional<(String | Document)>; + /** + * Specify which document the operation replaces if the query matches multiple + * documents. The first document matched by the sort order will be replaced. + * + * This option is sent only if the caller explicitly provides a value. The default is to not send a value. + * This option is only supported by servers >= 8.0. Older servers will report an error for using this option. + * + * @see https://www.mongodb.com/docs/manual/reference/command/update/ + */ + sort: Optional; + /** * When true, creates a new document if no document matches the query. * @@ -2391,7 +2413,7 @@ aforementioned allowance in the SemVer spec. ## Changelog -- 2024-08-30: Add sort option to `updateOne`. +- 2024-08-30: Add sort option to `replaceOne` and `updateOne`. - 2024-02-20: Migrated from reStructuredText to Markdown. diff --git a/source/crud/tests/unified/bulkWrite-replaceOne-sort.json b/source/crud/tests/unified/bulkWrite-replaceOne-sort.json new file mode 100644 index 0000000000..c0bd383514 --- /dev/null +++ b/source/crud/tests/unified/bulkWrite-replaceOne-sort.json @@ -0,0 +1,239 @@ +{ + "description": "BulkWrite replaceOne-sort", + "schemaVersion": "1.0", + "createEntities": [ + { + "client": { + "id": "client0", + "observeEvents": [ + "commandStartedEvent", + "commandSucceededEvent" + ] + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "crud-tests" + } + }, + { + "collection": { + "id": "collection0", + "database": "database0", + "collectionName": "coll0" + } + } + ], + "initialData": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + } + ] + } + ], + "tests": [ + { + "description": "BulkWrite replaceOne with sort option", + "runOnRequirements": [ + { + "minServerVersion": "8.0" + } + ], + "operations": [ + { + "object": "collection0", + "name": "bulkWrite", + "arguments": { + "requests": [ + { + "replaceOne": { + "filter": { + "_id": { + "$gt": 1 + } + }, + "sort": { + "_id": -1 + }, + "replacement": { + "x": 1 + } + } + } + ] + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "update": "coll0", + "updates": [ + { + "q": { + "_id": { + "$gt": 1 + } + }, + "u": { + "x": 1 + }, + "sort": { + "_id": -1 + }, + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false + } + } + ] + } + } + }, + { + "commandSucceededEvent": { + "reply": { + "ok": 1, + "n": 1 + }, + "commandName": "update" + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 1 + } + ] + } + ] + }, + { + "description": "BulkWrite replaceOne with sort option unsupported (server-side error)", + "runOnRequirements": [ + { + "maxServerVersion": "7.99" + } + ], + "operations": [ + { + "object": "collection0", + "name": "bulkWrite", + "arguments": { + "requests": [ + { + "replaceOne": { + "filter": { + "_id": { + "$gt": 1 + } + }, + "sort": { + "_id": -1 + }, + "replacement": { + "x": 1 + } + } + } + ] + }, + "expectError": { + "isClientError": false + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "update": "coll0", + "updates": [ + { + "q": { + "_id": { + "$gt": 1 + } + }, + "u": { + "x": 1 + }, + "sort": { + "_id": -1 + }, + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + } + ] + } + ] + } + ] +} diff --git a/source/crud/tests/unified/bulkWrite-replaceOne-sort.yml b/source/crud/tests/unified/bulkWrite-replaceOne-sort.yml new file mode 100644 index 0000000000..9594166f5b --- /dev/null +++ b/source/crud/tests/unified/bulkWrite-replaceOne-sort.yml @@ -0,0 +1,94 @@ +description: BulkWrite replaceOne-sort + +schemaVersion: "1.0" + +createEntities: + - client: + id: client0 + observeEvents: [ commandStartedEvent, commandSucceededEvent ] + - database: + id: database0 + client: client0 + databaseName: crud-tests + - collection: + id: collection0 + database: database0 + collectionName: coll0 + +initialData: + - collectionName: coll0 + databaseName: crud-tests + documents: + - { _id: 1, x: 11 } + - { _id: 2, x: 22 } + - { _id: 3, x: 33 } + +tests: + - description: BulkWrite replaceOne with sort option + runOnRequirements: + - minServerVersion: "8.0" + operations: + - object: collection0 + name: bulkWrite + arguments: + requests: + - replaceOne: + filter: { _id: {$gt: 1 } } + sort: { _id: -1 } + replacement: { x: 1 } + expectEvents: + - client: client0 + events: + - commandStartedEvent: + command: + update: coll0 + updates: + - q: { _id: { $gt: 1 } } + u: { x: 1 } + sort: { _id: -1 } + multi: { $$unsetOrMatches: false } + upsert: { $$unsetOrMatches: false } + - commandSucceededEvent: + reply: { ok: 1, n: 1 } + commandName: update + outcome: + - collectionName: coll0 + databaseName: crud-tests + documents: + - { _id: 1, x: 11 } + - { _id: 2, x: 22 } + - { _id: 3, x: 1 } + + - description: BulkWrite replaceOne with sort option unsupported (server-side error) + runOnRequirements: + - maxServerVersion: "7.99" + operations: + - object: collection0 + name: bulkWrite + arguments: + requests: + - replaceOne: + filter: { _id: { $gt: 1 } } + sort: { _id: -1 } + replacement: { x: 1 } + expectError: + isClientError: false + expectEvents: + - client: client0 + events: + - commandStartedEvent: + command: + update: coll0 + updates: + - q: { _id: { $gt: 1 } } + u: { x: 1 } + sort: { _id: -1 } + multi: { $$unsetOrMatches: false } + upsert: { $$unsetOrMatches: false } + outcome: + - collectionName: coll0 + databaseName: crud-tests + documents: + - { _id: 1, x: 11 } + - { _id: 2, x: 22 } + - { _id: 3, x: 33 } diff --git a/source/crud/tests/unified/bulkWrite-updateOne-sort.json b/source/crud/tests/unified/bulkWrite-updateOne-sort.json index 4ea4f26665..f78bd3bf3e 100644 --- a/source/crud/tests/unified/bulkWrite-updateOne-sort.json +++ b/source/crud/tests/unified/bulkWrite-updateOne-sort.json @@ -187,7 +187,6 @@ ] }, "expectError": { - "errorContains": "'update.updates.sort' is an unknown field", "isClientError": false } } diff --git a/source/crud/tests/unified/bulkWrite-updateOne-sort.yml b/source/crud/tests/unified/bulkWrite-updateOne-sort.yml index 91fd201c8c..9446986fab 100644 --- a/source/crud/tests/unified/bulkWrite-updateOne-sort.yml +++ b/source/crud/tests/unified/bulkWrite-updateOne-sort.yml @@ -1,11 +1,11 @@ description: BulkWrite updateOne-sort + schemaVersion: "1.0" + createEntities: - client: id: client0 - observeEvents: - - commandStartedEvent - - commandSucceededEvent + observeEvents: [ commandStartedEvent, commandSucceededEvent ] - database: id: database0 client: client0 @@ -14,16 +14,15 @@ createEntities: id: collection0 database: database0 collectionName: coll0 + initialData: - collectionName: coll0 databaseName: crud-tests documents: - - _id: 1 - x: 11 - - _id: 2 - x: 22 - - _id: 3 - x: 33 + - { _id: 1, x: 11 } + - { _id: 2, x: 22 } + - { _id: 3, x: 33 } + tests: - description: BulkWrite updateOne with sort option runOnRequirements: @@ -34,14 +33,9 @@ tests: arguments: requests: - updateOne: - filter: - _id: - $gt: 1 - sort: - _id: -1 - update: - - $set: - x: 1 + filter: { _id: { $gt: 1 } } + sort: { _id: -1 } + update: [ $set: { x: 1 } ] expectEvents: - client: client0 events: @@ -49,18 +43,11 @@ tests: command: update: coll0 updates: - - q: - _id: - $gt: 1 - u: - - $set: - x: 1 - sort: - _id: -1 - multi: - $$unsetOrMatches: false - upsert: - $$unsetOrMatches: false + - q: { _id: { $gt: 1 } } + u: [ $set: { x: 1 } ] + sort: { _id: -1 } + multi: { $$unsetOrMatches: false } + upsert: { $$unsetOrMatches: false } - commandSucceededEvent: reply: { ok: 1, n: 1 } commandName: update @@ -68,12 +55,10 @@ tests: - collectionName: coll0 databaseName: crud-tests documents: - - _id: 1 - x: 11 - - _id: 2 - x: 22 - - _id: 3 - x: 1 + - { _id: 1, x: 11 } + - { _id: 2, x: 22 } + - { _id: 3, x: 1 } + - description: BulkWrite updateOne with sort option unsupported (server-side error) runOnRequirements: - maxServerVersion: "7.99" @@ -83,16 +68,10 @@ tests: arguments: requests: - updateOne: - filter: - _id: - $gt: 1 - sort: - _id: -1 - update: - - $set: - x: 1 + filter: { _id: { $gt: 1 } } + sort: { _id: -1 } + update: [ $set: { x: 1 } ] expectError: - errorContains: "'update.updates.sort' is an unknown field" isClientError: false expectEvents: - client: client0 @@ -101,25 +80,15 @@ tests: command: update: coll0 updates: - - q: - _id: - $gt: 1 - u: - - $set: - x: 1 - sort: - _id: -1 - multi: - $$unsetOrMatches: false - upsert: - $$unsetOrMatches: false + - q: { _id: { $gt: 1 } } + u: [ $set: { x: 1 } ] + sort: { _id: -1 } + multi: { $$unsetOrMatches: false } + upsert: { $$unsetOrMatches: false } outcome: - collectionName: coll0 databaseName: crud-tests documents: - - _id: 1 - x: 11 - - _id: 2 - x: 22 - - _id: 3 - x: 33 + - { _id: 1, x: 11 } + - { _id: 2, x: 22 } + - { _id: 3, x: 33 } diff --git a/source/crud/tests/unified/replaceOne-sort.json b/source/crud/tests/unified/replaceOne-sort.json new file mode 100644 index 0000000000..cf2271dda5 --- /dev/null +++ b/source/crud/tests/unified/replaceOne-sort.json @@ -0,0 +1,232 @@ +{ + "description": "replaceOne-sort", + "schemaVersion": "1.0", + "createEntities": [ + { + "client": { + "id": "client0", + "observeEvents": [ + "commandStartedEvent", + "commandSucceededEvent" + ] + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "crud-tests" + } + }, + { + "collection": { + "id": "collection0", + "database": "database0", + "collectionName": "coll0" + } + } + ], + "initialData": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + } + ] + } + ], + "tests": [ + { + "description": "ReplaceOne with sort option", + "runOnRequirements": [ + { + "minServerVersion": "8.0" + } + ], + "operations": [ + { + "name": "replaceOne", + "object": "collection0", + "arguments": { + "filter": { + "_id": { + "$gt": 1 + } + }, + "sort": { + "_id": -1 + }, + "replacement": { + "x": 1 + } + }, + "expectResult": { + "matchedCount": 1, + "modifiedCount": 1, + "upsertedCount": 0 + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "update": "coll0", + "updates": [ + { + "q": { + "_id": { + "$gt": 1 + } + }, + "u": { + "x": 1 + }, + "sort": { + "_id": -1 + }, + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false + } + } + ] + } + } + }, + { + "commandSucceededEvent": { + "reply": { + "ok": 1, + "n": 1 + }, + "commandName": "update" + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 1 + } + ] + } + ] + }, + { + "description": "replaceOne with sort option unsupported (server-side error)", + "runOnRequirements": [ + { + "maxServerVersion": "7.99" + } + ], + "operations": [ + { + "name": "replaceOne", + "object": "collection0", + "arguments": { + "filter": { + "_id": { + "$gt": 1 + } + }, + "sort": { + "_id": -1 + }, + "replacement": { + "x": 1 + } + }, + "expectError": { + "isClientError": false + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "update": "coll0", + "updates": [ + { + "q": { + "_id": { + "$gt": 1 + } + }, + "u": { + "x": 1 + }, + "sort": { + "_id": -1 + }, + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false + } + } + ] + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + } + ] + } + ] + } + ] +} diff --git a/source/crud/tests/unified/replaceOne-sort.yml b/source/crud/tests/unified/replaceOne-sort.yml new file mode 100644 index 0000000000..3395b795e8 --- /dev/null +++ b/source/crud/tests/unified/replaceOne-sort.yml @@ -0,0 +1,94 @@ +description: replaceOne-sort + +schemaVersion: "1.0" + +createEntities: + - client: + id: client0 + observeEvents: [ commandStartedEvent, commandSucceededEvent ] + - database: + id: database0 + client: client0 + databaseName: crud-tests + - collection: + id: collection0 + database: database0 + collectionName: coll0 + +initialData: + - collectionName: coll0 + databaseName: crud-tests + documents: + - { _id: 1, x: 11 } + - { _id: 2, x: 22 } + - { _id: 3, x: 33 } + +tests: + - description: ReplaceOne with sort option + runOnRequirements: + - minServerVersion: "8.0" + operations: + - name: replaceOne + object: collection0 + arguments: + filter: { _id: { $gt: 1 } } + sort: { _id: -1 } + replacement: { x: 1 } + expectResult: + matchedCount: 1 + modifiedCount: 1 + upsertedCount: 0 + expectEvents: + - client: client0 + events: + - commandStartedEvent: + command: + update: coll0 + updates: + - q: { _id: { $gt: 1 } } + u: { x: 1 } + sort: { _id: -1 } + multi: { $$unsetOrMatches: false } + upsert: { $$unsetOrMatches: false } + - commandSucceededEvent: + reply: { ok: 1, n: 1 } + commandName: update + outcome: + - collectionName: coll0 + databaseName: crud-tests + documents: + - { _id: 1, x: 11 } + - { _id: 2, x: 22 } + - { _id: 3, x: 1 } + + - description: replaceOne with sort option unsupported (server-side error) + runOnRequirements: + - maxServerVersion: "7.99" + operations: + - name: replaceOne + object: collection0 + arguments: + filter: { _id: { $gt: 1 } } + sort: { _id: -1 } + replacement: { x: 1 } + expectError: + isClientError: false + expectEvents: + - client: client0 + events: + - commandStartedEvent: + command: + update: coll0 + updates: + - q: { _id: { $gt: 1 } } + u: { x: 1 } + sort: { _id: -1 } + multi: { $$unsetOrMatches: false } + upsert: { $$unsetOrMatches: false } + outcome: + - collectionName: coll0 + databaseName: crud-tests + documents: + - { _id: 1, x: 11 } + - { _id: 2, x: 22 } + - { _id: 3, x: 33 } diff --git a/source/crud/tests/unified/updateMany-sort.json b/source/crud/tests/unified/updateMany-sort.json index 4cf1f05c63..d54fba4ba6 100644 --- a/source/crud/tests/unified/updateMany-sort.json +++ b/source/crud/tests/unified/updateMany-sort.json @@ -48,98 +48,6 @@ "tests": [ { "description": "UpdateMany with sort option unsupported", - "runOnRequirements": [ - { - "minServerVersion": "8.0" - } - ], - "operations": [ - { - "name": "updateMany", - "object": "collection0", - "arguments": { - "filter": { - "_id": { - "$gt": 1 - } - }, - "sort": { - "_id": -1 - }, - "update": { - "$inc": { - "x": 1 - } - } - }, - "expectError": { - "isError": true - } - } - ], - "expectEvents": [ - { - "client": "client0", - "events": [ - { - "commandStartedEvent": { - "command": { - "update": "coll0", - "updates": [ - { - "q": { - "_id": { - "$gt": 1 - } - }, - "u": { - "$inc": { - "x": 1 - } - }, - "sort": { - "_id": -1 - }, - "multi": true, - "upsert": { - "$$unsetOrMatches": false - } - } - ] - } - } - } - ] - } - ], - "outcome": [ - { - "collectionName": "coll0", - "databaseName": "crud-tests", - "documents": [ - { - "_id": 1, - "x": 11 - }, - { - "_id": 2, - "x": 22 - }, - { - "_id": 3, - "x": 33 - } - ] - } - ] - }, - { - "description": "updateMany with sort option unsupported (server-side error)", - "runOnRequirements": [ - { - "maxServerVersion": "7.99" - } - ], "operations": [ { "name": "updateMany", @@ -160,7 +68,6 @@ } }, "expectError": { - "errorContains": "'update.updates.sort' is an unknown field", "isClientError": false } } diff --git a/source/crud/tests/unified/updateMany-sort.yml b/source/crud/tests/unified/updateMany-sort.yml index c2bda64e9b..eb576e2b79 100644 --- a/source/crud/tests/unified/updateMany-sort.yml +++ b/source/crud/tests/unified/updateMany-sort.yml @@ -1,5 +1,7 @@ description: updateMany-sort + schemaVersion: "1.0" + createEntities: - client: id: client0 @@ -13,79 +15,25 @@ createEntities: id: collection0 database: database0 collectionName: coll0 + initialData: - collectionName: coll0 databaseName: crud-tests documents: - - _id: 1 - x: 11 - - _id: 2 - x: 22 - - _id: 3 - x: 33 + - { _id: 1, x: 11 } + - { _id: 2, x: 22 } + - { _id: 3, x: 33 } + tests: - description: UpdateMany with sort option unsupported - runOnRequirements: - - minServerVersion: "8.0" operations: - name: updateMany object: collection0 arguments: - filter: - _id: - $gt: 1 - sort: - _id: -1 - update: - $inc: - x: 1 + filter: { _id: { $gt: 1 } } + sort: { _id: -1 } + update: { $inc: { x: 1 } } expectError: - isError: true - expectEvents: - - client: client0 - events: - - commandStartedEvent: - command: - update: coll0 - updates: - - q: - _id: - $gt: 1 - u: - $inc: - x: 1 - sort: - _id: -1 - multi: true - upsert: - $$unsetOrMatches: false - outcome: - - collectionName: coll0 - databaseName: crud-tests - documents: - - _id: 1 - x: 11 - - _id: 2 - x: 22 - - _id: 3 - x: 33 - - description: updateMany with sort option unsupported (server-side error) - runOnRequirements: - - maxServerVersion: "7.99" - operations: - - name: updateMany - object: collection0 - arguments: - filter: - _id: - $gt: 1 - sort: - _id: -1 - update: - $inc: - x: 1 - expectError: - errorContains: "'update.updates.sort' is an unknown field" isClientError: false expectEvents: - client: client0 @@ -94,24 +42,15 @@ tests: command: update: coll0 updates: - - q: - _id: - $gt: 1 - u: - $inc: - x: 1 - sort: - _id: -1 + - q: { _id: { $gt: 1 } } + u: { $inc: { x: 1 } } + sort: { _id: -1 } multi: true - upsert: - $$unsetOrMatches: false + upsert: { $$unsetOrMatches: false } outcome: - collectionName: coll0 databaseName: crud-tests documents: - - _id: 1 - x: 11 - - _id: 2 - x: 22 - - _id: 3 - x: 33 + - { _id: 1, x: 11 } + - { _id: 2, x: 22 } + - { _id: 3, x: 33 } diff --git a/source/crud/tests/unified/updateOne-sort.json b/source/crud/tests/unified/updateOne-sort.json index 9fe28f69f1..8fe4f50b94 100644 --- a/source/crud/tests/unified/updateOne-sort.json +++ b/source/crud/tests/unified/updateOne-sort.json @@ -174,7 +174,6 @@ } }, "expectError": { - "errorContains": "'update.updates.sort' is an unknown field", "isClientError": false } } diff --git a/source/crud/tests/unified/updateOne-sort.yml b/source/crud/tests/unified/updateOne-sort.yml index 2354daa7ad..a278575fa5 100644 --- a/source/crud/tests/unified/updateOne-sort.yml +++ b/source/crud/tests/unified/updateOne-sort.yml @@ -1,5 +1,7 @@ description: updateOne-sort + schemaVersion: "1.0" + createEntities: - client: id: client0 @@ -14,16 +16,15 @@ createEntities: id: collection0 database: database0 collectionName: coll0 + initialData: - collectionName: coll0 databaseName: crud-tests documents: - - _id: 1 - x: 11 - - _id: 2 - x: 22 - - _id: 3 - x: 33 + - { _id: 1, x: 11 } + - { _id: 2, x: 22 } + - { _id: 3, x: 33 } + tests: - description: UpdateOne with sort option runOnRequirements: @@ -32,14 +33,9 @@ tests: - name: updateOne object: collection0 arguments: - filter: - _id: - $gt: 1 - sort: - _id: -1 - update: - $inc: - x: 1 + filter: { _id: { $gt: 1 } } + sort: { _id: -1 } + update: { $inc: { x: 1 } } expectResult: matchedCount: 1 modifiedCount: 1 @@ -51,18 +47,11 @@ tests: command: update: coll0 updates: - - q: - _id: - $gt: 1 - u: - $inc: - x: 1 - sort: - _id: -1 - multi: - $$unsetOrMatches: false - upsert: - $$unsetOrMatches: false + - q: { _id: { $gt: 1 } } + u: { $inc: { x: 1 } } + sort: { _id: -1 } + multi: { $$unsetOrMatches: false } + upsert: { $$unsetOrMatches: false } - commandSucceededEvent: reply: { ok: 1, n: 1 } commandName: update @@ -70,12 +59,10 @@ tests: - collectionName: coll0 databaseName: crud-tests documents: - - _id: 1 - x: 11 - - _id: 2 - x: 22 - - _id: 3 - x: 34 + - { _id: 1, x: 11 } + - { _id: 2, x: 22 } + - { _id: 3, x: 34 } + - description: updateOne with sort option unsupported (server-side error) runOnRequirements: - maxServerVersion: "7.99" @@ -83,16 +70,10 @@ tests: - name: updateOne object: collection0 arguments: - filter: - _id: - $gt: 1 - sort: - _id: -1 - update: - $inc: - x: 1 + filter: { _id: { $gt: 1 } } + sort: { _id: -1 } + update: { $inc: { x: 1 } } expectError: - errorContains: "'update.updates.sort' is an unknown field" isClientError: false expectEvents: - client: client0 @@ -101,25 +82,15 @@ tests: command: update: coll0 updates: - - q: - _id: - $gt: 1 - u: - $inc: - x: 1 - sort: - _id: -1 - multi: - $$unsetOrMatches: false - upsert: - $$unsetOrMatches: false + - q: { _id: { $gt: 1 } } + u: { $inc: { x: 1 } } + sort: { _id: -1 } + multi: { $$unsetOrMatches: false } + upsert: { $$unsetOrMatches: false } outcome: - collectionName: coll0 databaseName: crud-tests documents: - - _id: 1 - x: 11 - - _id: 2 - x: 22 - - _id: 3 - x: 33 + - { _id: 1, x: 11 } + - { _id: 2, x: 22 } + - { _id: 3, x: 33 } From 7e57bd411050596d31dab20210826bf013da1f23 Mon Sep 17 00:00:00 2001 From: Qingyang Hu Date: Mon, 9 Sep 2024 18:58:42 -0400 Subject: [PATCH 03/10] Separate `UpdateOptions` to `UpdateOneOptions` and `UpdateManyOptions`. --- source/crud/crud.md | 91 +++++++++++- .../crud/tests/unified/updateMany-sort.json | 132 ------------------ source/crud/tests/unified/updateMany-sort.yml | 56 -------- 3 files changed, 85 insertions(+), 194 deletions(-) delete mode 100644 source/crud/tests/unified/updateMany-sort.json delete mode 100644 source/crud/tests/unified/updateMany-sort.yml diff --git a/source/crud/crud.md b/source/crud/crud.md index cb50e9b493..19b6f31189 100644 --- a/source/crud/crud.md +++ b/source/crud/crud.md @@ -60,8 +60,7 @@ A non-exhaustive list of acceptable deviations are as follows: - Using named parameters instead of an options hash. For instance, `collection.find({x:1}, sort: {a: -1})`. - When using an `Options` class, if multiple `Options` classes are structurally equatable, it is permissible to - consolidate them into one with a clear name. For instance, it would be permissible to use the name `UpdateOptions` as - the options for `UpdateOne` and `UpdateMany`. + consolidate them into one with a clear name. - Using a fluent style builder for find or aggregate: @@ -888,7 +887,7 @@ interface Collection { * @see https://www.mongodb.com/docs/manual/reference/command/update/ * @throws WriteException */ - updateOne(filter: Document, update: (Document | Document[]), options: Optional): Optional; + updateOne(filter: Document, update: (Document | Document[]), options: Optional): Optional; /** * Updates multiple documents. @@ -896,7 +895,7 @@ interface Collection { * @see https://www.mongodb.com/docs/manual/reference/command/update/ * @throws WriteException */ - updateMany(filter: Document, update: (Document | Document[]), options: Optional): Optional; + updateMany(filter: Document, update: (Document | Document[]), options: Optional): Optional; } class BulkWriteOptions { @@ -992,7 +991,7 @@ class InsertManyOptions { comment: Optional; } -class UpdateOptions { +class UpdateOneOptions { /** * A set of filters specifying to which array elements an update should apply. @@ -1083,6 +1082,85 @@ class UpdateOptions { sort: Optional; } +class UpdateManyOptions { + + /** + * A set of filters specifying to which array elements an update should apply. + * + * This option is sent only if the caller explicitly provides a value. The default is to not send a value. + * For servers < 3.6, the driver MUST raise an error if the caller explicitly provides a value. + * For unacknowledged writes using OP_UPDATE, the driver MUST raise an error if the caller explicitly provides a value. + * + * @see https://www.mongodb.com/docs/manual/reference/command/update/ + */ + arrayFilters: Optional>; + + /** + * If true, allows the write to opt-out of document level validation. + * + * This option is sent only if the caller explicitly provides a true value. The default is to not send a value. + * For servers < 3.2, this option is ignored and not sent as document validation is not available. + * For unacknowledged writes using OP_UPDATE, the driver MUST raise an error if the caller explicitly provides a value. + */ + bypassDocumentValidation: Optional; + + /** + * Specifies a collation. + * + * This option is sent only if the caller explicitly provides a value. The default is to not send a value. + * For servers < 3.4, the driver MUST raise an error if the caller explicitly provides a value. + * For unacknowledged writes using OP_UPDATE, the driver MUST raise an error if the caller explicitly provides a value. + * + * @see https://www.mongodb.com/docs/manual/reference/command/update/ + */ + collation: Optional; + + /** + * The index to use. Specify either the index name as a string or the index key pattern. + * If specified, then the query system will only consider plans using the hinted index. + * + * This option is sent only if the caller explicitly provides a value. The default is to not send a value. + * This option is only supported by servers >= 4.2. Older servers >= 3.4 will report an error for using this option. + * For servers < 3.4, the driver MUST raise an error if the caller explicitly provides a value. + * For unacknowledged writes using OP_UPDATE, the driver MUST raise an error if the caller explicitly provides a value. + * For unacknowledged writes using OP_MSG and servers < 4.2, the driver MUST raise an error if the caller explicitly provides a value. + * + * @see https://www.mongodb.com/docs/manual/reference/command/update/ + */ + hint: Optional<(String | Document)>; + + /** + * When true, creates a new document if no document matches the query. + * + * This option is sent only if the caller explicitly provides a value. The default is to not send a value. + * + * @see https://www.mongodb.com/docs/manual/reference/command/update/ + */ + upsert: Optional; + + /** + * Map of parameter names and values. Values must be constant or closed + * expressions that do not reference document fields. Parameters can then be + * accessed as variables in an aggregate expression context (e.g. "$$var"). + * + * This option is sent only if the caller explicitly provides a value. The default is to not send a value. + * This option is only supported by servers >= 5.0. Older servers >= 2.6 (and possibly earlier) will report an error for using this option. + * + * @see https://www.mongodb.com/docs/manual/reference/command/update/ + */ + let: Optional; + + /** + * Enables users to specify an arbitrary comment to help trace the operation through + * the database profiler, currentOp and logs. The default is to not send a value. + * + * The comment can be any valid BSON type for server versions 4.4 and above. + * Server versions prior to 4.4 do not support comment for update command, + * and providing one will result in a server-side error. + */ + comment: Optional; +} + class ReplaceOptions { /** @@ -2413,7 +2491,8 @@ aforementioned allowance in the SemVer spec. ## Changelog -- 2024-08-30: Add sort option to `replaceOne` and `updateOne`. +- 2024-08-30: Add sort option to `replaceOne` and `updateOne`. Separate `UpdateOptions`\ + to `UpdateOneOptions` and `UpdateManyOptions`. - 2024-02-20: Migrated from reStructuredText to Markdown. diff --git a/source/crud/tests/unified/updateMany-sort.json b/source/crud/tests/unified/updateMany-sort.json deleted file mode 100644 index d54fba4ba6..0000000000 --- a/source/crud/tests/unified/updateMany-sort.json +++ /dev/null @@ -1,132 +0,0 @@ -{ - "description": "updateMany-sort", - "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, - "x": 11 - }, - { - "_id": 2, - "x": 22 - }, - { - "_id": 3, - "x": 33 - } - ] - } - ], - "tests": [ - { - "description": "UpdateMany with sort option unsupported", - "operations": [ - { - "name": "updateMany", - "object": "collection0", - "arguments": { - "filter": { - "_id": { - "$gt": 1 - } - }, - "sort": { - "_id": -1 - }, - "update": { - "$inc": { - "x": 1 - } - } - }, - "expectError": { - "isClientError": false - } - } - ], - "expectEvents": [ - { - "client": "client0", - "events": [ - { - "commandStartedEvent": { - "command": { - "update": "coll0", - "updates": [ - { - "q": { - "_id": { - "$gt": 1 - } - }, - "u": { - "$inc": { - "x": 1 - } - }, - "sort": { - "_id": -1 - }, - "multi": true, - "upsert": { - "$$unsetOrMatches": false - } - } - ] - } - } - } - ] - } - ], - "outcome": [ - { - "collectionName": "coll0", - "databaseName": "crud-tests", - "documents": [ - { - "_id": 1, - "x": 11 - }, - { - "_id": 2, - "x": 22 - }, - { - "_id": 3, - "x": 33 - } - ] - } - ] - } - ] -} diff --git a/source/crud/tests/unified/updateMany-sort.yml b/source/crud/tests/unified/updateMany-sort.yml deleted file mode 100644 index eb576e2b79..0000000000 --- a/source/crud/tests/unified/updateMany-sort.yml +++ /dev/null @@ -1,56 +0,0 @@ -description: updateMany-sort - -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, x: 11 } - - { _id: 2, x: 22 } - - { _id: 3, x: 33 } - -tests: - - description: UpdateMany with sort option unsupported - operations: - - name: updateMany - object: collection0 - arguments: - filter: { _id: { $gt: 1 } } - sort: { _id: -1 } - update: { $inc: { x: 1 } } - expectError: - isClientError: false - expectEvents: - - client: client0 - events: - - commandStartedEvent: - command: - update: coll0 - updates: - - q: { _id: { $gt: 1 } } - u: { $inc: { x: 1 } } - sort: { _id: -1 } - multi: true - upsert: { $$unsetOrMatches: false } - outcome: - - collectionName: coll0 - databaseName: crud-tests - documents: - - { _id: 1, x: 11 } - - { _id: 2, x: 22 } - - { _id: 3, x: 33 } From 0e3e444d5a78c9c25105b77b40a4dbf87d9371f5 Mon Sep 17 00:00:00 2001 From: Qingyang Hu Date: Mon, 9 Sep 2024 19:15:47 -0400 Subject: [PATCH 04/10] Format crud.md --- source/crud/crud.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/crud/crud.md b/source/crud/crud.md index 19b6f31189..e1548742f1 100644 --- a/source/crud/crud.md +++ b/source/crud/crud.md @@ -2491,8 +2491,8 @@ aforementioned allowance in the SemVer spec. ## Changelog -- 2024-08-30: Add sort option to `replaceOne` and `updateOne`. Separate `UpdateOptions`\ - to `UpdateOneOptions` and `UpdateManyOptions`. +- 2024-08-30: Add sort option to `replaceOne` and `updateOne`. Separate `UpdateOptions` to `UpdateOneOptions` and + `UpdateManyOptions`. - 2024-02-20: Migrated from reStructuredText to Markdown. From a0db5783cc141c66218a3487f7ced72c7c034402 Mon Sep 17 00:00:00 2001 From: Qingyang Hu Date: Mon, 30 Sep 2024 10:19:44 -0400 Subject: [PATCH 05/10] add client bulk write tests --- source/crud/crud.md | 81 +-------- .../client-bulkWrite-replaceOne-sort.json | 159 +++++++++++++++++ .../client-bulkWrite-replaceOne-sort.yml | 73 ++++++++ .../client-bulkWrite-updateOne-sort.json | 163 ++++++++++++++++++ .../client-bulkWrite-updateOne-sort.yml | 73 ++++++++ 5 files changed, 469 insertions(+), 80 deletions(-) create mode 100644 source/crud/tests/unified/client-bulkWrite-replaceOne-sort.json create mode 100644 source/crud/tests/unified/client-bulkWrite-replaceOne-sort.yml create mode 100644 source/crud/tests/unified/client-bulkWrite-updateOne-sort.json create mode 100644 source/crud/tests/unified/client-bulkWrite-updateOne-sort.yml diff --git a/source/crud/crud.md b/source/crud/crud.md index e1548742f1..cb5350219d 100644 --- a/source/crud/crud.md +++ b/source/crud/crud.md @@ -991,7 +991,7 @@ class InsertManyOptions { comment: Optional; } -class UpdateOneOptions { +class UpdateOptions { /** * A set of filters specifying to which array elements an update should apply. @@ -1082,85 +1082,6 @@ class UpdateOneOptions { sort: Optional; } -class UpdateManyOptions { - - /** - * A set of filters specifying to which array elements an update should apply. - * - * This option is sent only if the caller explicitly provides a value. The default is to not send a value. - * For servers < 3.6, the driver MUST raise an error if the caller explicitly provides a value. - * For unacknowledged writes using OP_UPDATE, the driver MUST raise an error if the caller explicitly provides a value. - * - * @see https://www.mongodb.com/docs/manual/reference/command/update/ - */ - arrayFilters: Optional>; - - /** - * If true, allows the write to opt-out of document level validation. - * - * This option is sent only if the caller explicitly provides a true value. The default is to not send a value. - * For servers < 3.2, this option is ignored and not sent as document validation is not available. - * For unacknowledged writes using OP_UPDATE, the driver MUST raise an error if the caller explicitly provides a value. - */ - bypassDocumentValidation: Optional; - - /** - * Specifies a collation. - * - * This option is sent only if the caller explicitly provides a value. The default is to not send a value. - * For servers < 3.4, the driver MUST raise an error if the caller explicitly provides a value. - * For unacknowledged writes using OP_UPDATE, the driver MUST raise an error if the caller explicitly provides a value. - * - * @see https://www.mongodb.com/docs/manual/reference/command/update/ - */ - collation: Optional; - - /** - * The index to use. Specify either the index name as a string or the index key pattern. - * If specified, then the query system will only consider plans using the hinted index. - * - * This option is sent only if the caller explicitly provides a value. The default is to not send a value. - * This option is only supported by servers >= 4.2. Older servers >= 3.4 will report an error for using this option. - * For servers < 3.4, the driver MUST raise an error if the caller explicitly provides a value. - * For unacknowledged writes using OP_UPDATE, the driver MUST raise an error if the caller explicitly provides a value. - * For unacknowledged writes using OP_MSG and servers < 4.2, the driver MUST raise an error if the caller explicitly provides a value. - * - * @see https://www.mongodb.com/docs/manual/reference/command/update/ - */ - hint: Optional<(String | Document)>; - - /** - * When true, creates a new document if no document matches the query. - * - * This option is sent only if the caller explicitly provides a value. The default is to not send a value. - * - * @see https://www.mongodb.com/docs/manual/reference/command/update/ - */ - upsert: Optional; - - /** - * Map of parameter names and values. Values must be constant or closed - * expressions that do not reference document fields. Parameters can then be - * accessed as variables in an aggregate expression context (e.g. "$$var"). - * - * This option is sent only if the caller explicitly provides a value. The default is to not send a value. - * This option is only supported by servers >= 5.0. Older servers >= 2.6 (and possibly earlier) will report an error for using this option. - * - * @see https://www.mongodb.com/docs/manual/reference/command/update/ - */ - let: Optional; - - /** - * Enables users to specify an arbitrary comment to help trace the operation through - * the database profiler, currentOp and logs. The default is to not send a value. - * - * The comment can be any valid BSON type for server versions 4.4 and above. - * Server versions prior to 4.4 do not support comment for update command, - * and providing one will result in a server-side error. - */ - comment: Optional; -} - class ReplaceOptions { /** diff --git a/source/crud/tests/unified/client-bulkWrite-replaceOne-sort.json b/source/crud/tests/unified/client-bulkWrite-replaceOne-sort.json new file mode 100644 index 0000000000..515bceae84 --- /dev/null +++ b/source/crud/tests/unified/client-bulkWrite-replaceOne-sort.json @@ -0,0 +1,159 @@ +{ + "description": "client bulkWrite updateOne-sort", + "schemaVersion": "1.0", + "runOnRequirements": [ + { + "minServerVersion": "8.0" + } + ], + "createEntities": [ + { + "client": { + "id": "client0", + "observeEvents": [ + "commandStartedEvent", + "commandSucceededEvent" + ] + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "crud-tests" + } + }, + { + "collection": { + "id": "collection0", + "database": "database0", + "collectionName": "coll0" + } + } + ], + "initialData": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + } + ] + } + ], + "tests": [ + { + "description": "client bulkWrite replaceOne with sort option", + "operations": [ + { + "object": "client0", + "name": "clientBulkWrite", + "arguments": { + "models": [ + { + "replaceOne": { + "namespace": "crud-tests.coll0", + "filter": { + "_id": { + "$gt": 1 + } + }, + "sort": { + "_id": -1 + }, + "replacement": { + "x": 1 + } + } + } + ] + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "commandName": "bulkWrite", + "databaseName": "admin", + "command": { + "bulkWrite": 1, + "ops": [ + { + "update": 0, + "filter": { + "_id": { + "$gt": 1 + } + }, + "updateMods": { + "x": 1 + }, + "sort": { + "_id": -1 + }, + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false + } + } + ], + "nsInfo": [ + { + "ns": "crud-tests.coll0" + } + ] + } + } + }, + { + "commandSucceededEvent": { + "reply": { + "ok": 1, + "nErrors": 0, + "nMatched": 1, + "nModified": 1 + }, + "commandName": "bulkWrite" + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 1 + } + ] + } + ] + } + ] +} diff --git a/source/crud/tests/unified/client-bulkWrite-replaceOne-sort.yml b/source/crud/tests/unified/client-bulkWrite-replaceOne-sort.yml new file mode 100644 index 0000000000..058c5d1f4e --- /dev/null +++ b/source/crud/tests/unified/client-bulkWrite-replaceOne-sort.yml @@ -0,0 +1,73 @@ +description: client bulkWrite updateOne-sort + +schemaVersion: "1.0" + +runOnRequirements: + - minServerVersion: "8.0" + +createEntities: + - client: + id: client0 + observeEvents: + - commandStartedEvent + - commandSucceededEvent + - database: + id: database0 + client: client0 + databaseName: crud-tests + - collection: + id: collection0 + database: database0 + collectionName: coll0 + +initialData: + - collectionName: coll0 + databaseName: crud-tests + documents: + - { _id: 1, x: 11 } + - { _id: 2, x: 22 } + - { _id: 3, x: 33 } + +tests: + - description: client bulkWrite replaceOne with sort option + operations: + - object: client0 + name: clientBulkWrite + arguments: + models: + - replaceOne: + namespace: crud-tests.coll0 + filter: { _id: { $gt: 1 } } + sort: { _id: -1 } + replacement: { x: 1 } + expectEvents: + - client: client0 + events: + - commandStartedEvent: + commandName: bulkWrite + databaseName: admin + command: + bulkWrite: 1 + ops: + - update: 0 + filter: { _id: { $gt: 1 } } + updateMods: { x: 1 } + sort: { _id: -1 } + multi: { $$unsetOrMatches: false } + upsert: { $$unsetOrMatches: false } + nsInfo: + - ns: crud-tests.coll0 + - commandSucceededEvent: + reply: + ok: 1 + nErrors: 0 + nMatched: 1 + nModified: 1 + commandName: bulkWrite + outcome: + - collectionName: coll0 + databaseName: crud-tests + documents: + - { _id: 1, x: 11 } + - { _id: 2, x: 22 } + - { _id: 3, x: 1 } diff --git a/source/crud/tests/unified/client-bulkWrite-updateOne-sort.json b/source/crud/tests/unified/client-bulkWrite-updateOne-sort.json new file mode 100644 index 0000000000..688bb01027 --- /dev/null +++ b/source/crud/tests/unified/client-bulkWrite-updateOne-sort.json @@ -0,0 +1,163 @@ +{ + "description": "client bulkWrite updateOne-sort", + "schemaVersion": "1.0", + "runOnRequirements": [ + { + "minServerVersion": "8.0" + } + ], + "createEntities": [ + { + "client": { + "id": "client0", + "observeEvents": [ + "commandStartedEvent", + "commandSucceededEvent" + ] + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "crud-tests" + } + }, + { + "collection": { + "id": "collection0", + "database": "database0", + "collectionName": "coll0" + } + } + ], + "initialData": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + } + ] + } + ], + "tests": [ + { + "description": "client bulkWrite updateOne with sort option", + "operations": [ + { + "object": "client0", + "name": "clientBulkWrite", + "arguments": { + "models": [ + { + "updateOne": { + "namespace": "crud-tests.coll0", + "filter": { + "_id": { + "$gt": 1 + } + }, + "sort": { + "_id": -1 + }, + "update": { + "$inc": { + "x": 1 + } + } + } + } + ] + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "commandName": "bulkWrite", + "databaseName": "admin", + "command": { + "bulkWrite": 1, + "ops": [ + { + "update": 0, + "filter": { + "_id": { + "$gt": 1 + } + }, + "updateMods": { + "$inc": { + "x": 1 + } + }, + "sort": { + "_id": -1 + }, + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false + } + } + ], + "nsInfo": [ + { + "ns": "crud-tests.coll0" + } + ] + } + } + }, + { + "commandSucceededEvent": { + "reply": { + "ok": 1, + "nErrors": 0, + "nMatched": 1, + "nModified": 1 + }, + "commandName": "bulkWrite" + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 34 + } + ] + } + ] + } + ] +} diff --git a/source/crud/tests/unified/client-bulkWrite-updateOne-sort.yml b/source/crud/tests/unified/client-bulkWrite-updateOne-sort.yml new file mode 100644 index 0000000000..a1e476563d --- /dev/null +++ b/source/crud/tests/unified/client-bulkWrite-updateOne-sort.yml @@ -0,0 +1,73 @@ +description: client bulkWrite updateOne-sort + +schemaVersion: "1.0" + +runOnRequirements: + - minServerVersion: "8.0" + +createEntities: + - client: + id: client0 + observeEvents: + - commandStartedEvent + - commandSucceededEvent + - database: + id: database0 + client: client0 + databaseName: crud-tests + - collection: + id: collection0 + database: database0 + collectionName: coll0 + +initialData: + - collectionName: coll0 + databaseName: crud-tests + documents: + - { _id: 1, x: 11 } + - { _id: 2, x: 22 } + - { _id: 3, x: 33 } + +tests: + - description: client bulkWrite updateOne with sort option + operations: + - object: client0 + name: clientBulkWrite + arguments: + models: + - updateOne: + namespace: crud-tests.coll0 + filter: { _id: { $gt: 1 } } + sort: { _id: -1 } + update: { $inc: { x: 1 } } + expectEvents: + - client: client0 + events: + - commandStartedEvent: + commandName: bulkWrite + databaseName: admin + command: + bulkWrite: 1 + ops: + - update: 0 + filter: { _id: { $gt: 1 } } + updateMods: { $inc: { x: 1 } } + sort: { _id: -1 } + multi: { $$unsetOrMatches: false } + upsert: { $$unsetOrMatches: false } + nsInfo: + - ns: crud-tests.coll0 + - commandSucceededEvent: + reply: + ok: 1 + nErrors: 0 + nMatched: 1 + nModified: 1 + commandName: bulkWrite + outcome: + - collectionName: coll0 + databaseName: crud-tests + documents: + - { _id: 1, x: 11 } + - { _id: 2, x: 22 } + - { _id: 3, x: 34 } From f2d9e6ae4a60a74d6c396c0468116ea41152eaba Mon Sep 17 00:00:00 2001 From: Qingyang Hu Date: Mon, 30 Sep 2024 10:36:28 -0400 Subject: [PATCH 06/10] update client bulk write --- source/crud/bulk-write.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/source/crud/bulk-write.md b/source/crud/bulk-write.md index 5918e6417c..2736ca2445 100644 --- a/source/crud/bulk-write.md +++ b/source/crud/bulk-write.md @@ -90,6 +90,14 @@ class UpdateOneModel implements WriteModel { * value is false. */ upsert: Optional; + + /** + * Specify which document the operation updates if the query matches multiple + * documents. The first document matched by the sort order will be updated. + * + * This option is only sent if the caller explicitly provides a value. + */ + sort: Optional; } class UpdateManyModel implements WriteModel { @@ -167,6 +175,14 @@ class ReplaceOneModel implements WriteModel { * value is false. */ upsert: Optional; + + /** + * Specify which document the operation replaces if the query matches multiple + * documents. The first document matched by the sort order will be replaced. + * + * This option is only sent if the caller explicitly provides a value. + */ + sort: Optional; } class DeleteOneModel implements WriteModel { @@ -871,6 +887,8 @@ batch-splitting to standardize implementations across drivers and simplify batch ## **Changelog** +- 2024-09-30: Add sort option to `replaceOne` and `updateOne`. + - 2024-09-25: Add `collation` field to `update` document and clarify usage of `updateMods`. - 2024-09-25: Update the `partialResult` population logic to account for ordered bulk writes. From 9479fa1c520aee2fb5a175c9f0973aabaa93b089 Mon Sep 17 00:00:00 2001 From: Qingyang Hu Date: Mon, 30 Sep 2024 10:45:38 -0400 Subject: [PATCH 07/10] update crud.md --- source/crud/crud.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/crud/crud.md b/source/crud/crud.md index e4987a6ae8..1c7e051f07 100644 --- a/source/crud/crud.md +++ b/source/crud/crud.md @@ -61,7 +61,8 @@ A non-exhaustive list of acceptable deviations are as follows: - Using named parameters instead of an options hash. For instance, `collection.find({x:1}, sort: {a: -1})`. - When using an `Options` class, if multiple `Options` classes are structurally equatable, it is permissible to - consolidate them into one with a clear name. + consolidate them into one with a clear name. For instance, it would be permissible to use the name `UpdateOptions` as + the options for `UpdateOne` and `UpdateMany`. - Using a fluent style builder for find or aggregate: From f017c77329deee684bbc558db22eb2bce4a9857c Mon Sep 17 00:00:00 2001 From: Qingyang Hu Date: Tue, 1 Oct 2024 12:00:50 -0400 Subject: [PATCH 08/10] use aliases in yaml files --- .../unified/bulkWrite-replaceOne-sort.yml | 40 +++++++++---------- .../unified/bulkWrite-updateOne-sort.yml | 38 +++++++++--------- .../client-bulkWrite-replaceOne-sort.yml | 33 ++++++++------- .../client-bulkWrite-updateOne-sort.yml | 33 ++++++++------- source/crud/tests/unified/replaceOne-sort.yml | 38 +++++++++--------- source/crud/tests/unified/updateOne-sort.yml | 38 +++++++++--------- 6 files changed, 113 insertions(+), 107 deletions(-) diff --git a/source/crud/tests/unified/bulkWrite-replaceOne-sort.yml b/source/crud/tests/unified/bulkWrite-replaceOne-sort.yml index 9594166f5b..6f326fe043 100644 --- a/source/crud/tests/unified/bulkWrite-replaceOne-sort.yml +++ b/source/crud/tests/unified/bulkWrite-replaceOne-sort.yml @@ -4,20 +4,20 @@ schemaVersion: "1.0" createEntities: - client: - id: client0 + id: &client0 client0 observeEvents: [ commandStartedEvent, commandSucceededEvent ] - database: - id: database0 - client: client0 - databaseName: crud-tests + id: &database0 database0 + client: *client0 + databaseName: &database0Name crud-tests - collection: - id: collection0 - database: database0 - collectionName: coll0 + id: &collection0 collection0 + database: *database0 + collectionName: &collection0Name coll0 initialData: - - collectionName: coll0 - databaseName: crud-tests + - collectionName: *collection0Name + databaseName: *database0Name documents: - { _id: 1, x: 11 } - { _id: 2, x: 22 } @@ -28,20 +28,20 @@ tests: runOnRequirements: - minServerVersion: "8.0" operations: - - object: collection0 + - object: *collection0 name: bulkWrite arguments: requests: - replaceOne: - filter: { _id: {$gt: 1 } } + filter: { _id: { $gt: 1 } } sort: { _id: -1 } replacement: { x: 1 } expectEvents: - - client: client0 + - client: *client0 events: - commandStartedEvent: command: - update: coll0 + update: *collection0Name updates: - q: { _id: { $gt: 1 } } u: { x: 1 } @@ -52,8 +52,8 @@ tests: reply: { ok: 1, n: 1 } commandName: update outcome: - - collectionName: coll0 - databaseName: crud-tests + - collectionName: *collection0Name + databaseName: *database0Name documents: - { _id: 1, x: 11 } - { _id: 2, x: 22 } @@ -63,7 +63,7 @@ tests: runOnRequirements: - maxServerVersion: "7.99" operations: - - object: collection0 + - object: *collection0 name: bulkWrite arguments: requests: @@ -74,11 +74,11 @@ tests: expectError: isClientError: false expectEvents: - - client: client0 + - client: *client0 events: - commandStartedEvent: command: - update: coll0 + update: *collection0Name updates: - q: { _id: { $gt: 1 } } u: { x: 1 } @@ -86,8 +86,8 @@ tests: multi: { $$unsetOrMatches: false } upsert: { $$unsetOrMatches: false } outcome: - - collectionName: coll0 - databaseName: crud-tests + - collectionName: *collection0Name + databaseName: *database0Name documents: - { _id: 1, x: 11 } - { _id: 2, x: 22 } diff --git a/source/crud/tests/unified/bulkWrite-updateOne-sort.yml b/source/crud/tests/unified/bulkWrite-updateOne-sort.yml index 9446986fab..72bc814d69 100644 --- a/source/crud/tests/unified/bulkWrite-updateOne-sort.yml +++ b/source/crud/tests/unified/bulkWrite-updateOne-sort.yml @@ -4,20 +4,20 @@ schemaVersion: "1.0" createEntities: - client: - id: client0 + id: &client0 client0 observeEvents: [ commandStartedEvent, commandSucceededEvent ] - database: - id: database0 - client: client0 - databaseName: crud-tests + id: &database0 database0 + client: *client0 + databaseName: &database0Name crud-tests - collection: - id: collection0 - database: database0 - collectionName: coll0 + id: &collection0 collection0 + database: *database0 + collectionName: &collection0Name coll0 initialData: - - collectionName: coll0 - databaseName: crud-tests + - collectionName: *collection0Name + databaseName: *database0Name documents: - { _id: 1, x: 11 } - { _id: 2, x: 22 } @@ -28,7 +28,7 @@ tests: runOnRequirements: - minServerVersion: "8.0" operations: - - object: collection0 + - object: *collection0 name: bulkWrite arguments: requests: @@ -37,11 +37,11 @@ tests: sort: { _id: -1 } update: [ $set: { x: 1 } ] expectEvents: - - client: client0 + - client: *client0 events: - commandStartedEvent: command: - update: coll0 + update: *collection0Name updates: - q: { _id: { $gt: 1 } } u: [ $set: { x: 1 } ] @@ -52,8 +52,8 @@ tests: reply: { ok: 1, n: 1 } commandName: update outcome: - - collectionName: coll0 - databaseName: crud-tests + - collectionName: *collection0Name + databaseName: *database0Name documents: - { _id: 1, x: 11 } - { _id: 2, x: 22 } @@ -63,7 +63,7 @@ tests: runOnRequirements: - maxServerVersion: "7.99" operations: - - object: collection0 + - object: *collection0 name: bulkWrite arguments: requests: @@ -74,11 +74,11 @@ tests: expectError: isClientError: false expectEvents: - - client: client0 + - client: *client0 events: - commandStartedEvent: command: - update: coll0 + update: *collection0Name updates: - q: { _id: { $gt: 1 } } u: [ $set: { x: 1 } ] @@ -86,8 +86,8 @@ tests: multi: { $$unsetOrMatches: false } upsert: { $$unsetOrMatches: false } outcome: - - collectionName: coll0 - databaseName: crud-tests + - collectionName: *collection0Name + databaseName: *database0Name documents: - { _id: 1, x: 11 } - { _id: 2, x: 22 } diff --git a/source/crud/tests/unified/client-bulkWrite-replaceOne-sort.yml b/source/crud/tests/unified/client-bulkWrite-replaceOne-sort.yml index 058c5d1f4e..6ca82f84ee 100644 --- a/source/crud/tests/unified/client-bulkWrite-replaceOne-sort.yml +++ b/source/crud/tests/unified/client-bulkWrite-replaceOne-sort.yml @@ -7,41 +7,44 @@ runOnRequirements: createEntities: - client: - id: client0 + id: &client0 client0 observeEvents: - commandStartedEvent - commandSucceededEvent - database: - id: database0 - client: client0 - databaseName: crud-tests + id: &database0 database0 + client: *client0 + databaseName: &database0Name crud-tests - collection: - id: collection0 - database: database0 - collectionName: coll0 + id: &collection0 collection0 + database: *database0 + collectionName: &collection0Name coll0 initialData: - - collectionName: coll0 - databaseName: crud-tests + - collectionName: *collection0Name + databaseName: *database0Name documents: - { _id: 1, x: 11 } - { _id: 2, x: 22 } - { _id: 3, x: 33 } +_yamlAnchors: + namespace: &namespace "crud-tests.coll0" + tests: - description: client bulkWrite replaceOne with sort option operations: - - object: client0 + - object: *client0 name: clientBulkWrite arguments: models: - replaceOne: - namespace: crud-tests.coll0 + namespace: *namespace filter: { _id: { $gt: 1 } } sort: { _id: -1 } replacement: { x: 1 } expectEvents: - - client: client0 + - client: *client0 events: - commandStartedEvent: commandName: bulkWrite @@ -56,7 +59,7 @@ tests: multi: { $$unsetOrMatches: false } upsert: { $$unsetOrMatches: false } nsInfo: - - ns: crud-tests.coll0 + - ns: *namespace - commandSucceededEvent: reply: ok: 1 @@ -65,8 +68,8 @@ tests: nModified: 1 commandName: bulkWrite outcome: - - collectionName: coll0 - databaseName: crud-tests + - collectionName: *collection0Name + databaseName: *database0Name documents: - { _id: 1, x: 11 } - { _id: 2, x: 22 } diff --git a/source/crud/tests/unified/client-bulkWrite-updateOne-sort.yml b/source/crud/tests/unified/client-bulkWrite-updateOne-sort.yml index a1e476563d..bbacefc327 100644 --- a/source/crud/tests/unified/client-bulkWrite-updateOne-sort.yml +++ b/source/crud/tests/unified/client-bulkWrite-updateOne-sort.yml @@ -7,41 +7,44 @@ runOnRequirements: createEntities: - client: - id: client0 + id: &client0 client0 observeEvents: - commandStartedEvent - commandSucceededEvent - database: - id: database0 - client: client0 - databaseName: crud-tests + id: &database0 database0 + client: *client0 + databaseName: &database0Name crud-tests - collection: - id: collection0 - database: database0 - collectionName: coll0 + id: &collection0 collection0 + database: *database0 + collectionName: &collection0Name coll0 initialData: - - collectionName: coll0 - databaseName: crud-tests + - collectionName: *collection0Name + databaseName: *database0Name documents: - { _id: 1, x: 11 } - { _id: 2, x: 22 } - { _id: 3, x: 33 } +_yamlAnchors: + namespace: &namespace "crud-tests.coll0" + tests: - description: client bulkWrite updateOne with sort option operations: - - object: client0 + - object: *client0 name: clientBulkWrite arguments: models: - updateOne: - namespace: crud-tests.coll0 + namespace: *namespace filter: { _id: { $gt: 1 } } sort: { _id: -1 } update: { $inc: { x: 1 } } expectEvents: - - client: client0 + - client: *client0 events: - commandStartedEvent: commandName: bulkWrite @@ -56,7 +59,7 @@ tests: multi: { $$unsetOrMatches: false } upsert: { $$unsetOrMatches: false } nsInfo: - - ns: crud-tests.coll0 + - ns: *namespace - commandSucceededEvent: reply: ok: 1 @@ -65,8 +68,8 @@ tests: nModified: 1 commandName: bulkWrite outcome: - - collectionName: coll0 - databaseName: crud-tests + - collectionName: *collection0Name + databaseName: *database0Name documents: - { _id: 1, x: 11 } - { _id: 2, x: 22 } diff --git a/source/crud/tests/unified/replaceOne-sort.yml b/source/crud/tests/unified/replaceOne-sort.yml index 3395b795e8..f4b10fbaf9 100644 --- a/source/crud/tests/unified/replaceOne-sort.yml +++ b/source/crud/tests/unified/replaceOne-sort.yml @@ -4,20 +4,20 @@ schemaVersion: "1.0" createEntities: - client: - id: client0 + id: &client0 client0 observeEvents: [ commandStartedEvent, commandSucceededEvent ] - database: - id: database0 - client: client0 - databaseName: crud-tests + id: &database0 database0 + client: *client0 + databaseName: &database0Name crud-tests - collection: - id: collection0 - database: database0 - collectionName: coll0 + id: &collection0 collection0 + database: *database0 + collectionName: &collection0Name coll0 initialData: - - collectionName: coll0 - databaseName: crud-tests + - collectionName: *collection0Name + databaseName: *database0Name documents: - { _id: 1, x: 11 } - { _id: 2, x: 22 } @@ -29,7 +29,7 @@ tests: - minServerVersion: "8.0" operations: - name: replaceOne - object: collection0 + object: *collection0 arguments: filter: { _id: { $gt: 1 } } sort: { _id: -1 } @@ -39,11 +39,11 @@ tests: modifiedCount: 1 upsertedCount: 0 expectEvents: - - client: client0 + - client: *client0 events: - commandStartedEvent: command: - update: coll0 + update: *collection0Name updates: - q: { _id: { $gt: 1 } } u: { x: 1 } @@ -54,8 +54,8 @@ tests: reply: { ok: 1, n: 1 } commandName: update outcome: - - collectionName: coll0 - databaseName: crud-tests + - collectionName: *collection0Name + databaseName: *database0Name documents: - { _id: 1, x: 11 } - { _id: 2, x: 22 } @@ -66,7 +66,7 @@ tests: - maxServerVersion: "7.99" operations: - name: replaceOne - object: collection0 + object: *collection0 arguments: filter: { _id: { $gt: 1 } } sort: { _id: -1 } @@ -74,11 +74,11 @@ tests: expectError: isClientError: false expectEvents: - - client: client0 + - client: *client0 events: - commandStartedEvent: command: - update: coll0 + update: *collection0Name updates: - q: { _id: { $gt: 1 } } u: { x: 1 } @@ -86,8 +86,8 @@ tests: multi: { $$unsetOrMatches: false } upsert: { $$unsetOrMatches: false } outcome: - - collectionName: coll0 - databaseName: crud-tests + - collectionName: *collection0Name + databaseName: *database0Name documents: - { _id: 1, x: 11 } - { _id: 2, x: 22 } diff --git a/source/crud/tests/unified/updateOne-sort.yml b/source/crud/tests/unified/updateOne-sort.yml index a278575fa5..a14e1df1d2 100644 --- a/source/crud/tests/unified/updateOne-sort.yml +++ b/source/crud/tests/unified/updateOne-sort.yml @@ -4,22 +4,22 @@ schemaVersion: "1.0" createEntities: - client: - id: client0 + id: &client0 client0 observeEvents: - commandStartedEvent - commandSucceededEvent - database: - id: database0 - client: client0 - databaseName: crud-tests + id: &database0 database0 + client: *client0 + databaseName: &database0Name crud-tests - collection: - id: collection0 - database: database0 - collectionName: coll0 + id: &collection0 collection0 + database: *database0 + collectionName: &collection0Name coll0 initialData: - - collectionName: coll0 - databaseName: crud-tests + - collectionName: *collection0Name + databaseName: *database0Name documents: - { _id: 1, x: 11 } - { _id: 2, x: 22 } @@ -31,7 +31,7 @@ tests: - minServerVersion: "8.0" operations: - name: updateOne - object: collection0 + object: *collection0 arguments: filter: { _id: { $gt: 1 } } sort: { _id: -1 } @@ -41,11 +41,11 @@ tests: modifiedCount: 1 upsertedCount: 0 expectEvents: - - client: client0 + - client: *client0 events: - commandStartedEvent: command: - update: coll0 + update: *collection0Name updates: - q: { _id: { $gt: 1 } } u: { $inc: { x: 1 } } @@ -56,8 +56,8 @@ tests: reply: { ok: 1, n: 1 } commandName: update outcome: - - collectionName: coll0 - databaseName: crud-tests + - collectionName: *collection0Name + databaseName: *database0Name documents: - { _id: 1, x: 11 } - { _id: 2, x: 22 } @@ -68,7 +68,7 @@ tests: - maxServerVersion: "7.99" operations: - name: updateOne - object: collection0 + object: *collection0 arguments: filter: { _id: { $gt: 1 } } sort: { _id: -1 } @@ -76,11 +76,11 @@ tests: expectError: isClientError: false expectEvents: - - client: client0 + - client: *client0 events: - commandStartedEvent: command: - update: coll0 + update: *collection0Name updates: - q: { _id: { $gt: 1 } } u: { $inc: { x: 1 } } @@ -88,8 +88,8 @@ tests: multi: { $$unsetOrMatches: false } upsert: { $$unsetOrMatches: false } outcome: - - collectionName: coll0 - databaseName: crud-tests + - collectionName: *collection0Name + databaseName: *database0Name documents: - { _id: 1, x: 11 } - { _id: 2, x: 22 } From 28aee1b252752589a243f67926a7b54b7a250ad5 Mon Sep 17 00:00:00 2001 From: Qingyang Hu Date: Tue, 1 Oct 2024 13:02:11 -0400 Subject: [PATCH 09/10] minor updates --- source/crud/tests/unified/client-bulkWrite-replaceOne-sort.json | 2 +- source/crud/tests/unified/client-bulkWrite-replaceOne-sort.yml | 2 +- source/crud/tests/unified/client-bulkWrite-updateOne-sort.json | 2 +- source/crud/tests/unified/client-bulkWrite-updateOne-sort.yml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source/crud/tests/unified/client-bulkWrite-replaceOne-sort.json b/source/crud/tests/unified/client-bulkWrite-replaceOne-sort.json index 515bceae84..1485a67bc6 100644 --- a/source/crud/tests/unified/client-bulkWrite-replaceOne-sort.json +++ b/source/crud/tests/unified/client-bulkWrite-replaceOne-sort.json @@ -1,6 +1,6 @@ { "description": "client bulkWrite updateOne-sort", - "schemaVersion": "1.0", + "schemaVersion": "1.4", "runOnRequirements": [ { "minServerVersion": "8.0" diff --git a/source/crud/tests/unified/client-bulkWrite-replaceOne-sort.yml b/source/crud/tests/unified/client-bulkWrite-replaceOne-sort.yml index 6ca82f84ee..45ef30045c 100644 --- a/source/crud/tests/unified/client-bulkWrite-replaceOne-sort.yml +++ b/source/crud/tests/unified/client-bulkWrite-replaceOne-sort.yml @@ -1,6 +1,6 @@ description: client bulkWrite updateOne-sort -schemaVersion: "1.0" +schemaVersion: "1.4" runOnRequirements: - minServerVersion: "8.0" diff --git a/source/crud/tests/unified/client-bulkWrite-updateOne-sort.json b/source/crud/tests/unified/client-bulkWrite-updateOne-sort.json index 688bb01027..6672d7d50d 100644 --- a/source/crud/tests/unified/client-bulkWrite-updateOne-sort.json +++ b/source/crud/tests/unified/client-bulkWrite-updateOne-sort.json @@ -1,6 +1,6 @@ { "description": "client bulkWrite updateOne-sort", - "schemaVersion": "1.0", + "schemaVersion": "1.4", "runOnRequirements": [ { "minServerVersion": "8.0" diff --git a/source/crud/tests/unified/client-bulkWrite-updateOne-sort.yml b/source/crud/tests/unified/client-bulkWrite-updateOne-sort.yml index bbacefc327..ce24373972 100644 --- a/source/crud/tests/unified/client-bulkWrite-updateOne-sort.yml +++ b/source/crud/tests/unified/client-bulkWrite-updateOne-sort.yml @@ -1,6 +1,6 @@ description: client bulkWrite updateOne-sort -schemaVersion: "1.0" +schemaVersion: "1.4" runOnRequirements: - minServerVersion: "8.0" From 12cba41373cf028fb5177f08d7fd65004a4b3a4e Mon Sep 17 00:00:00 2001 From: Qingyang Hu Date: Tue, 1 Oct 2024 13:08:51 -0400 Subject: [PATCH 10/10] minor updates --- .../crud/tests/unified/client-bulkWrite-replaceOne-sort.json | 3 +++ source/crud/tests/unified/client-bulkWrite-updateOne-sort.json | 3 +++ 2 files changed, 6 insertions(+) diff --git a/source/crud/tests/unified/client-bulkWrite-replaceOne-sort.json b/source/crud/tests/unified/client-bulkWrite-replaceOne-sort.json index 1485a67bc6..53218c1f48 100644 --- a/source/crud/tests/unified/client-bulkWrite-replaceOne-sort.json +++ b/source/crud/tests/unified/client-bulkWrite-replaceOne-sort.json @@ -51,6 +51,9 @@ ] } ], + "_yamlAnchors": { + "namespace": "crud-tests.coll0" + }, "tests": [ { "description": "client bulkWrite replaceOne with sort option", diff --git a/source/crud/tests/unified/client-bulkWrite-updateOne-sort.json b/source/crud/tests/unified/client-bulkWrite-updateOne-sort.json index 6672d7d50d..4a07b8b97c 100644 --- a/source/crud/tests/unified/client-bulkWrite-updateOne-sort.json +++ b/source/crud/tests/unified/client-bulkWrite-updateOne-sort.json @@ -51,6 +51,9 @@ ] } ], + "_yamlAnchors": { + "namespace": "crud-tests.coll0" + }, "tests": [ { "description": "client bulkWrite updateOne with sort option",