diff --git a/.travis/install-extension.sh b/.travis/install-extension.sh index 684f2c489..9f99f71b5 100755 --- a/.travis/install-extension.sh +++ b/.travis/install-extension.sh @@ -16,14 +16,17 @@ tpecl () { fi } -if [ "x${DRIVER_BRANCH}" != "x" ]; then - echo "Compiling driver branch ${DRIVER_BRANCH}" +if [ "x${DRIVER_BRANCH}" != "x" ] || [ "x${DRIVER_REPO}" != "x" ]; then + CLONE_REPO=${DRIVER_REPO:-https://github.com/mongodb/mongo-php-driver} + CHECKOUT_BRANCH=${DRIVER_BRANCH:-master} + + echo "Compiling driver branch ${CHECKOUT_BRANCH} from repository ${CLONE_REPO}" mkdir -p /tmp/compile - git clone https://github.com/mongodb/mongo-php-driver /tmp/compile/mongo-php-driver + git clone ${CLONE_REPO} /tmp/compile/mongo-php-driver cd /tmp/compile/mongo-php-driver - git checkout ${DRIVER_BRANCH} + git checkout ${CHECKOUT_BRANCH} git submodule update --init phpize ./configure --enable-mongodb-developer-flags diff --git a/docs/includes/apiargs-MongoDBCollection-method-deleteMany-option.yaml b/docs/includes/apiargs-MongoDBCollection-method-deleteMany-option.yaml index 81e520bb6..55f6af9b3 100644 --- a/docs/includes/apiargs-MongoDBCollection-method-deleteMany-option.yaml +++ b/docs/includes/apiargs-MongoDBCollection-method-deleteMany-option.yaml @@ -2,6 +2,15 @@ source: file: apiargs-MongoDBCollection-common-option.yaml ref: collation --- +source: + file: apiargs-common-option.yaml + ref: hint +post: | + This option is available in MongoDB 4.4+ and will result in an exception at + execution time if specified for an older server version. + + .. versionadded:: 1.7 +--- source: file: apiargs-common-option.yaml ref: session diff --git a/docs/includes/apiargs-MongoDBCollection-method-deleteOne-option.yaml b/docs/includes/apiargs-MongoDBCollection-method-deleteOne-option.yaml index 81e520bb6..55f6af9b3 100644 --- a/docs/includes/apiargs-MongoDBCollection-method-deleteOne-option.yaml +++ b/docs/includes/apiargs-MongoDBCollection-method-deleteOne-option.yaml @@ -2,6 +2,15 @@ source: file: apiargs-MongoDBCollection-common-option.yaml ref: collation --- +source: + file: apiargs-common-option.yaml + ref: hint +post: | + This option is available in MongoDB 4.4+ and will result in an exception at + execution time if specified for an older server version. + + .. versionadded:: 1.7 +--- source: file: apiargs-common-option.yaml ref: session diff --git a/src/Operation/Delete.php b/src/Operation/Delete.php index 181351b0e..65cc6f6e9 100644 --- a/src/Operation/Delete.php +++ b/src/Operation/Delete.php @@ -27,6 +27,7 @@ use MongoDB\Exception\UnsupportedException; use function is_array; use function is_object; +use function is_string; use function MongoDB\server_supports_feature; /** @@ -43,6 +44,9 @@ class Delete implements Executable, Explainable /** @var integer */ private static $wireVersionForCollation = 5; + /** @var int */ + private static $wireVersionForHintServerSideError = 5; + /** @var string */ private $databaseName; @@ -68,6 +72,13 @@ class Delete implements Executable, Explainable * This is not supported for server versions < 3.4 and will result in an * exception at execution time if used. * + * * hint (string|document): The index to use. Specify either the index + * name as a string or the index key pattern as a document. If specified, + * then the query system will only consider plans using the hinted index. + * + * This is not supported for server versions < 4.4 and will result in an + * exception at execution time if used. + * * * session (MongoDB\Driver\Session): Client session. * * Sessions are not supported for server versions < 3.6. @@ -97,6 +108,10 @@ public function __construct($databaseName, $collectionName, $filter, $limit, arr throw InvalidArgumentException::invalidType('"collation" option', $options['collation'], 'array or object'); } + if (isset($options['hint']) && ! is_string($options['hint']) && ! is_array($options['hint']) && ! is_object($options['hint'])) { + throw InvalidArgumentException::invalidType('"hint" option', $options['hint'], ['string', 'array', 'object']); + } + if (isset($options['session']) && ! $options['session'] instanceof Session) { throw InvalidArgumentException::invalidType('"session" option', $options['session'], Session::class); } @@ -130,6 +145,13 @@ public function execute(Server $server) throw UnsupportedException::collationNotSupported(); } + /* Server versions >= 3.4.0 raise errors for unknown update + * options. For previous versions, the CRUD spec requires a client-side + * error. */ + if (isset($this->options['hint']) && ! server_supports_feature($server, self::$wireVersionForHintServerSideError)) { + throw UnsupportedException::hintNotSupported(); + } + $inTransaction = isset($this->options['session']) && $this->options['session']->isInTransaction(); if ($inTransaction && isset($this->options['writeConcern'])) { throw UnsupportedException::writeConcernNotSupportedInTransaction(); @@ -170,6 +192,10 @@ private function createDeleteOptions() $deleteOptions['collation'] = (object) $this->options['collation']; } + if (isset($this->options['hint'])) { + $deleteOptions['hint'] = $this->options['hint']; + } + return $deleteOptions; } diff --git a/src/Operation/DeleteMany.php b/src/Operation/DeleteMany.php index 96c8031e9..ffda516ca 100644 --- a/src/Operation/DeleteMany.php +++ b/src/Operation/DeleteMany.php @@ -45,6 +45,13 @@ class DeleteMany implements Executable, Explainable * This is not supported for server versions < 3.4 and will result in an * exception at execution time if used. * + * * hint (string|document): The index to use. Specify either the index + * name as a string or the index key pattern as a document. If specified, + * then the query system will only consider plans using the hinted index. + * + * This is not supported for server versions < 4.4 and will result in an + * exception at execution time if used. + * * * session (MongoDB\Driver\Session): Client session. * * Sessions are not supported for server versions < 3.6. diff --git a/src/Operation/DeleteOne.php b/src/Operation/DeleteOne.php index 3377a66d8..742a58f73 100644 --- a/src/Operation/DeleteOne.php +++ b/src/Operation/DeleteOne.php @@ -45,6 +45,13 @@ class DeleteOne implements Executable, Explainable * This is not supported for server versions < 3.4 and will result in an * exception at execution time if used. * + * * hint (string|document): The index to use. Specify either the index + * name as a string or the index key pattern as a document. If specified, + * then the query system will only consider plans using the hinted index. + * + * This is not supported for server versions < 4.4 and will result in an + * exception at execution time if used. + * * * session (MongoDB\Driver\Session): Client session. * * Sessions are not supported for server versions < 3.6. diff --git a/src/Operation/FindAndModify.php b/src/Operation/FindAndModify.php index 6a87a4790..9e1e5949d 100644 --- a/src/Operation/FindAndModify.php +++ b/src/Operation/FindAndModify.php @@ -55,6 +55,9 @@ class FindAndModify implements Executable, Explainable /** @var integer */ private static $wireVersionForDocumentLevelValidation = 4; + /** @var integer */ + private static $wireVersionForHint = 9; + /** @var integer */ private static $wireVersionForHintServerSideError = 8; @@ -99,8 +102,7 @@ class FindAndModify implements Executable, Explainable * name as a string or the index key pattern as a document. If specified, * then the query system will only consider plans using the hinted index. * - * This is only supported for update and replace operations (i.e. remove - * option is false) on server versions >= 4.4. Using this option in + * This is only supported on server versions >= 4.4. Using this option in * other contexts will result in an exception at execution time. * * * maxTimeMS (integer): The maximum amount of time to allow the query to @@ -246,7 +248,7 @@ public function execute(Server $server) * options (SERVER-40005), but the CRUD spec requires client-side errors * for server versions < 4.2. For later versions, we'll rely on the * server to either utilize the option or report its own error. */ - if (isset($this->options['hint']) && ! server_supports_feature($server, self::$wireVersionForHintServerSideError)) { + if (isset($this->options['hint']) && ! $this->isHintSupported($server)) { throw UnsupportedException::hintNotSupported(); } @@ -339,4 +341,20 @@ private function createOptions() return $options; } + + private function isAcknowledgedWriteConcern() : bool + { + if (! isset($this->options['writeConcern'])) { + return true; + } + + return $this->options['writeConcern']->getW() > 1 || $this->options['writeConcern']->getJournal(); + } + + private function isHintSupported(Server $server) : bool + { + $requiredWireVersion = $this->isAcknowledgedWriteConcern() ? self::$wireVersionForHintServerSideError : self::$wireVersionForHint; + + return server_supports_feature($server, $requiredWireVersion); + } } diff --git a/src/Operation/FindOneAndDelete.php b/src/Operation/FindOneAndDelete.php index 489ca3e95..88ed57f7e 100644 --- a/src/Operation/FindOneAndDelete.php +++ b/src/Operation/FindOneAndDelete.php @@ -46,6 +46,13 @@ class FindOneAndDelete implements Executable, Explainable * This is not supported for server versions < 3.4 and will result in an * exception at execution time if used. * + * * hint (string|document): The index to use. Specify either the index + * name as a string or the index key pattern as a document. If specified, + * then the query system will only consider plans using the hinted index. + * + * This is not supported for server versions < 4.4 and will result in an + * exception at execution time if used. + * * * maxTimeMS (integer): The maximum amount of time to allow the query to * run. * diff --git a/src/Operation/Update.php b/src/Operation/Update.php index 0dbff7227..b3b86e0c6 100644 --- a/src/Operation/Update.php +++ b/src/Operation/Update.php @@ -54,7 +54,7 @@ class Update implements Executable, Explainable private static $wireVersionForDocumentLevelValidation = 4; /** @var integer */ - private static $wireVersionForHint = 8; + private static $wireVersionForHintServerSideError = 5; /** @var string */ private $databaseName; @@ -202,7 +202,10 @@ public function execute(Server $server) throw UnsupportedException::collationNotSupported(); } - if (isset($this->options['hint']) && ! server_supports_feature($server, self::$wireVersionForHint)) { + /* Server versions >= 3.4.0 raise errors for unknown update + * options. For previous versions, the CRUD spec requires a client-side + * error. */ + if (isset($this->options['hint']) && ! server_supports_feature($server, self::$wireVersionForHintServerSideError)) { throw UnsupportedException::hintNotSupported(); } diff --git a/tests/SpecTests/CrudSpecTest.php b/tests/SpecTests/CrudSpecTest.php index cfbcb0147..a4a420c6a 100644 --- a/tests/SpecTests/CrudSpecTest.php +++ b/tests/SpecTests/CrudSpecTest.php @@ -73,7 +73,7 @@ public function testCrud(stdClass $test, array $runOn = null, array $data, $data } if (isset($test->expectations)) { - $commandExpectations = CommandExpectations::fromCrud($test->expectations); + $commandExpectations = CommandExpectations::fromCrud((array) $test->expectations); $commandExpectations->startMonitoring(); } diff --git a/tests/SpecTests/crud/bulkWrite-delete-hint-clientError.json b/tests/SpecTests/crud/bulkWrite-delete-hint-clientError.json new file mode 100644 index 000000000..cfeac904c --- /dev/null +++ b/tests/SpecTests/crud/bulkWrite-delete-hint-clientError.json @@ -0,0 +1,150 @@ +{ + "runOn": [ + { + "maxServerVersion": "3.3.99" + } + ], + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + }, + { + "_id": 4, + "x": 44 + } + ], + "collection_name": "BulkWrite_delete_hint", + "tests": [ + { + "description": "BulkWrite deleteOne with hints unsupported (client-side error)", + "operations": [ + { + "name": "bulkWrite", + "arguments": { + "requests": [ + { + "name": "deleteOne", + "arguments": { + "filter": { + "_id": 1 + }, + "hint": "_id_" + } + }, + { + "name": "deleteOne", + "arguments": { + "filter": { + "_id": 2 + }, + "hint": { + "_id": 1 + } + } + } + ], + "options": { + "ordered": true + } + }, + "error": true + } + ], + "expectations": [], + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + }, + { + "_id": 4, + "x": 44 + } + ] + } + } + }, + { + "description": "BulkWrite deleteMany with hints unsupported (client-side error)", + "operations": [ + { + "name": "bulkWrite", + "arguments": { + "requests": [ + { + "name": "deleteMany", + "arguments": { + "filter": { + "_id": { + "$lt": 3 + } + }, + "hint": "_id_" + } + }, + { + "name": "deleteMany", + "arguments": { + "filter": { + "_id": { + "$gte": 4 + } + }, + "hint": { + "_id": 1 + } + } + } + ], + "options": { + "ordered": true + } + }, + "error": true + } + ], + "expectations": [], + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + }, + { + "_id": 4, + "x": 44 + } + ] + } + } + } + ] +} diff --git a/tests/SpecTests/crud/bulkWrite-delete-hint-serverError.json b/tests/SpecTests/crud/bulkWrite-delete-hint-serverError.json new file mode 100644 index 000000000..c68973b0f --- /dev/null +++ b/tests/SpecTests/crud/bulkWrite-delete-hint-serverError.json @@ -0,0 +1,209 @@ +{ + "runOn": [ + { + "minServerVersion": "3.4.0", + "maxServerVersion": "4.3.3" + } + ], + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + }, + { + "_id": 4, + "x": 44 + } + ], + "collection_name": "BulkWrite_delete_hint", + "tests": [ + { + "description": "BulkWrite deleteOne with hints unsupported (server-side error)", + "operations": [ + { + "name": "bulkWrite", + "arguments": { + "requests": [ + { + "name": "deleteOne", + "arguments": { + "filter": { + "_id": 1 + }, + "hint": "_id_" + } + }, + { + "name": "deleteOne", + "arguments": { + "filter": { + "_id": 2 + }, + "hint": { + "_id": 1 + } + } + } + ], + "options": { + "ordered": true + } + }, + "error": true + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "delete": "BulkWrite_delete_hint", + "deletes": [ + { + "q": { + "_id": 1 + }, + "hint": "_id_", + "limit": 1 + }, + { + "q": { + "_id": 2 + }, + "hint": { + "_id": 1 + }, + "limit": 1 + } + ], + "ordered": true + } + } + } + ], + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + }, + { + "_id": 4, + "x": 44 + } + ] + } + } + }, + { + "description": "BulkWrite deleteMany with hints unsupported (server-side error)", + "operations": [ + { + "name": "bulkWrite", + "arguments": { + "requests": [ + { + "name": "deleteMany", + "arguments": { + "filter": { + "_id": { + "$lt": 3 + } + }, + "hint": "_id_" + } + }, + { + "name": "deleteMany", + "arguments": { + "filter": { + "_id": { + "$gte": 4 + } + }, + "hint": { + "_id": 1 + } + } + } + ], + "options": { + "ordered": true + } + }, + "error": true + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "delete": "BulkWrite_delete_hint", + "deletes": [ + { + "q": { + "_id": { + "$lt": 3 + } + }, + "hint": "_id_", + "limit": 0 + }, + { + "q": { + "_id": { + "$gte": 4 + } + }, + "hint": { + "_id": 1 + }, + "limit": 0 + } + ], + "ordered": true + } + } + } + ], + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + }, + { + "_id": 4, + "x": 44 + } + ] + } + } + } + ] +} diff --git a/tests/SpecTests/crud/bulkWrite-delete-hint.json b/tests/SpecTests/crud/bulkWrite-delete-hint.json new file mode 100644 index 000000000..ece3238fc --- /dev/null +++ b/tests/SpecTests/crud/bulkWrite-delete-hint.json @@ -0,0 +1,204 @@ +{ + "runOn": [ + { + "minServerVersion": "4.3.4" + } + ], + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + }, + { + "_id": 4, + "x": 44 + } + ], + "collection_name": "BulkWrite_delete_hint", + "tests": [ + { + "description": "BulkWrite deleteOne with hints", + "operations": [ + { + "name": "bulkWrite", + "arguments": { + "requests": [ + { + "name": "deleteOne", + "arguments": { + "filter": { + "_id": 1 + }, + "hint": "_id_" + } + }, + { + "name": "deleteOne", + "arguments": { + "filter": { + "_id": 2 + }, + "hint": { + "_id": 1 + } + } + } + ], + "options": { + "ordered": true + } + }, + "result": { + "deletedCount": 2, + "insertedCount": 0, + "insertedIds": {}, + "matchedCount": 0, + "modifiedCount": 0, + "upsertedCount": 0, + "upsertedIds": {} + } + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "delete": "BulkWrite_delete_hint", + "deletes": [ + { + "q": { + "_id": 1 + }, + "hint": "_id_", + "limit": 1 + }, + { + "q": { + "_id": 2 + }, + "hint": { + "_id": 1 + }, + "limit": 1 + } + ], + "ordered": true + } + } + } + ], + "outcome": { + "collection": { + "data": [ + { + "_id": 3, + "x": 33 + }, + { + "_id": 4, + "x": 44 + } + ] + } + } + }, + { + "description": "BulkWrite deleteMany with hints", + "operations": [ + { + "name": "bulkWrite", + "arguments": { + "requests": [ + { + "name": "deleteMany", + "arguments": { + "filter": { + "_id": { + "$lt": 3 + } + }, + "hint": "_id_" + } + }, + { + "name": "deleteMany", + "arguments": { + "filter": { + "_id": { + "$gte": 4 + } + }, + "hint": { + "_id": 1 + } + } + } + ], + "options": { + "ordered": true + } + }, + "result": { + "deletedCount": 3, + "insertedCount": 0, + "insertedIds": {}, + "matchedCount": 0, + "modifiedCount": 0, + "upsertedCount": 0, + "upsertedIds": {} + } + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "delete": "BulkWrite_delete_hint", + "deletes": [ + { + "q": { + "_id": { + "$lt": 3 + } + }, + "hint": "_id_", + "limit": 0 + }, + { + "q": { + "_id": { + "$gte": 4 + } + }, + "hint": { + "_id": 1 + }, + "limit": 0 + } + ], + "ordered": true + } + } + } + ], + "outcome": { + "collection": { + "data": [ + { + "_id": 3, + "x": 33 + } + ] + } + } + } + ] +} diff --git a/tests/SpecTests/crud/bulkWrite-update-hint-clientError.json b/tests/SpecTests/crud/bulkWrite-update-hint-clientError.json new file mode 100644 index 000000000..fa919ec51 --- /dev/null +++ b/tests/SpecTests/crud/bulkWrite-update-hint-clientError.json @@ -0,0 +1,235 @@ +{ + "runOn": [ + { + "maxServerVersion": "3.3.99" + } + ], + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + }, + { + "_id": 4, + "x": 44 + } + ], + "collection_name": "test_bulkwrite_update_hint", + "tests": [ + { + "description": "BulkWrite updateOne with update hints unsupported (client-side error)", + "operations": [ + { + "name": "bulkWrite", + "arguments": { + "requests": [ + { + "name": "updateOne", + "arguments": { + "filter": { + "_id": 1 + }, + "update": { + "$inc": { + "x": 1 + } + }, + "hint": "_id_" + } + }, + { + "name": "updateOne", + "arguments": { + "filter": { + "_id": 1 + }, + "update": { + "$inc": { + "x": 1 + } + }, + "hint": { + "_id": 1 + } + } + } + ], + "options": { + "ordered": true + } + }, + "error": true + } + ], + "expectations": [], + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + }, + { + "_id": 4, + "x": 44 + } + ] + } + } + }, + { + "description": "BulkWrite updateMany with update hints unsupported (client-side error)", + "operations": [ + { + "name": "bulkWrite", + "arguments": { + "requests": [ + { + "name": "updateMany", + "arguments": { + "filter": { + "_id": { + "$lt": 3 + } + }, + "update": { + "$inc": { + "x": 1 + } + }, + "hint": "_id_" + } + }, + { + "name": "updateMany", + "arguments": { + "filter": { + "_id": { + "$lt": 3 + } + }, + "update": { + "$inc": { + "x": 1 + } + }, + "hint": { + "_id": 1 + } + } + } + ], + "options": { + "ordered": true + } + }, + "error": true + } + ], + "expectations": [], + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + }, + { + "_id": 4, + "x": 44 + } + ] + } + } + }, + { + "description": "BulkWrite replaceOne with update hints unsupported (client-side error)", + "operations": [ + { + "name": "bulkWrite", + "arguments": { + "requests": [ + { + "name": "replaceOne", + "arguments": { + "filter": { + "_id": 3 + }, + "replacement": { + "x": 333 + }, + "hint": "_id_" + } + }, + { + "name": "replaceOne", + "arguments": { + "filter": { + "_id": 4 + }, + "replacement": { + "x": 444 + }, + "hint": { + "_id": 1 + } + } + } + ], + "options": { + "ordered": true + } + }, + "error": true + } + ], + "expectations": [], + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + }, + { + "_id": 4, + "x": 44 + } + ] + } + } + } + ] +} diff --git a/tests/SpecTests/crud/bulkWrite-update-hint-serverError.json b/tests/SpecTests/crud/bulkWrite-update-hint-serverError.json new file mode 100644 index 000000000..e8b96fffe --- /dev/null +++ b/tests/SpecTests/crud/bulkWrite-update-hint-serverError.json @@ -0,0 +1,343 @@ +{ + "runOn": [ + { + "minServerVersion": "3.4.0", + "maxServerVersion": "4.1.9" + } + ], + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + }, + { + "_id": 4, + "x": 44 + } + ], + "collection_name": "test_bulkwrite_update_hint", + "tests": [ + { + "description": "BulkWrite updateOne with update hints unsupported (server-side error)", + "operations": [ + { + "name": "bulkWrite", + "arguments": { + "requests": [ + { + "name": "updateOne", + "arguments": { + "filter": { + "_id": 1 + }, + "update": { + "$inc": { + "x": 1 + } + }, + "hint": "_id_" + } + }, + { + "name": "updateOne", + "arguments": { + "filter": { + "_id": 1 + }, + "update": { + "$inc": { + "x": 1 + } + }, + "hint": { + "_id": 1 + } + } + } + ], + "options": { + "ordered": true + } + }, + "error": true + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "update": "test_bulkwrite_update_hint", + "updates": [ + { + "q": { + "_id": 1 + }, + "u": { + "$inc": { + "x": 1 + } + }, + "hint": "_id_" + }, + { + "q": { + "_id": 1 + }, + "u": { + "$inc": { + "x": 1 + } + }, + "hint": { + "_id": 1 + } + } + ], + "ordered": true + } + } + } + ], + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + }, + { + "_id": 4, + "x": 44 + } + ] + } + } + }, + { + "description": "BulkWrite updateMany with update hints unsupported (server-side error)", + "operations": [ + { + "name": "bulkWrite", + "arguments": { + "requests": [ + { + "name": "updateMany", + "arguments": { + "filter": { + "_id": { + "$lt": 3 + } + }, + "update": { + "$inc": { + "x": 1 + } + }, + "hint": "_id_" + } + }, + { + "name": "updateMany", + "arguments": { + "filter": { + "_id": { + "$lt": 3 + } + }, + "update": { + "$inc": { + "x": 1 + } + }, + "hint": { + "_id": 1 + } + } + } + ], + "options": { + "ordered": true + } + }, + "error": true + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "update": "test_bulkwrite_update_hint", + "updates": [ + { + "q": { + "_id": { + "$lt": 3 + } + }, + "u": { + "$inc": { + "x": 1 + } + }, + "multi": true, + "hint": "_id_" + }, + { + "q": { + "_id": { + "$lt": 3 + } + }, + "u": { + "$inc": { + "x": 1 + } + }, + "multi": true, + "hint": { + "_id": 1 + } + } + ], + "ordered": true + } + } + } + ], + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + }, + { + "_id": 4, + "x": 44 + } + ] + } + } + }, + { + "description": "BulkWrite replaceOne with update hints unsupported (server-side error)", + "operations": [ + { + "name": "bulkWrite", + "arguments": { + "requests": [ + { + "name": "replaceOne", + "arguments": { + "filter": { + "_id": 3 + }, + "replacement": { + "x": 333 + }, + "hint": "_id_" + } + }, + { + "name": "replaceOne", + "arguments": { + "filter": { + "_id": 4 + }, + "replacement": { + "x": 444 + }, + "hint": { + "_id": 1 + } + } + } + ], + "options": { + "ordered": true + } + }, + "error": true + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "update": "test_bulkwrite_update_hint", + "updates": [ + { + "q": { + "_id": 3 + }, + "u": { + "x": 333 + }, + "hint": "_id_" + }, + { + "q": { + "_id": 4 + }, + "u": { + "x": 444 + }, + "hint": { + "_id": 1 + } + } + ], + "ordered": true + } + } + } + ], + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + }, + { + "_id": 4, + "x": 44 + } + ] + } + } + } + ] +} diff --git a/tests/SpecTests/crud/deleteMany-hint-clientError.json b/tests/SpecTests/crud/deleteMany-hint-clientError.json new file mode 100644 index 000000000..3a0d02566 --- /dev/null +++ b/tests/SpecTests/crud/deleteMany-hint-clientError.json @@ -0,0 +1,100 @@ +{ + "runOn": [ + { + "maxServerVersion": "3.3.99" + } + ], + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + } + ], + "collection_name": "DeleteMany_hint", + "tests": [ + { + "description": "DeleteMany with hint string unsupported (client-side error)", + "operations": [ + { + "object": "collection", + "name": "deleteMany", + "arguments": { + "filter": { + "_id": { + "$gt": 1 + } + }, + "hint": "_id_" + }, + "error": true + } + ], + "expectations": [], + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + } + ] + } + } + }, + { + "description": "DeleteMany with hint document unsupported (client-side error)", + "operations": [ + { + "object": "collection", + "name": "deleteMany", + "arguments": { + "filter": { + "_id": { + "$gt": 1 + } + }, + "hint": { + "_id": 1 + } + }, + "error": true + } + ], + "expectations": [], + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + } + ] + } + } + } + ] +} diff --git a/tests/SpecTests/crud/deleteMany-hint-serverError.json b/tests/SpecTests/crud/deleteMany-hint-serverError.json new file mode 100644 index 000000000..5829e86df --- /dev/null +++ b/tests/SpecTests/crud/deleteMany-hint-serverError.json @@ -0,0 +1,141 @@ +{ + "runOn": [ + { + "minServerVersion": "3.4.0", + "maxServerVersion": "4.3.3" + } + ], + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + } + ], + "collection_name": "DeleteMany_hint", + "tests": [ + { + "description": "DeleteMany with hint string unsupported (server-side error)", + "operations": [ + { + "object": "collection", + "name": "deleteMany", + "arguments": { + "filter": { + "_id": { + "$gt": 1 + } + }, + "hint": "_id_" + }, + "error": true + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "delete": "DeleteMany_hint", + "deletes": [ + { + "q": { + "_id": { + "$gt": 1 + } + }, + "hint": "_id_", + "limit": 0 + } + ] + } + } + } + ], + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + } + ] + } + } + }, + { + "description": "DeleteMany with hint document unsupported (server-side error)", + "operations": [ + { + "object": "collection", + "name": "deleteMany", + "arguments": { + "filter": { + "_id": { + "$gt": 1 + } + }, + "hint": { + "_id": 1 + } + }, + "error": true + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "delete": "DeleteMany_hint", + "deletes": [ + { + "q": { + "_id": { + "$gt": 1 + } + }, + "hint": { + "_id": 1 + }, + "limit": 0 + } + ] + } + } + } + ], + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + } + ] + } + } + } + ] +} diff --git a/tests/SpecTests/crud/deleteMany-hint.json b/tests/SpecTests/crud/deleteMany-hint.json new file mode 100644 index 000000000..51ee38606 --- /dev/null +++ b/tests/SpecTests/crud/deleteMany-hint.json @@ -0,0 +1,128 @@ +{ + "runOn": [ + { + "minServerVersion": "4.3.4" + } + ], + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + } + ], + "collection_name": "DeleteMany_hint", + "tests": [ + { + "description": "DeleteMany with hint string", + "operations": [ + { + "object": "collection", + "name": "deleteMany", + "arguments": { + "filter": { + "_id": { + "$gt": 1 + } + }, + "hint": "_id_" + }, + "result": { + "deletedCount": 2 + } + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "delete": "DeleteMany_hint", + "deletes": [ + { + "q": { + "_id": { + "$gt": 1 + } + }, + "hint": "_id_", + "limit": 0 + } + ] + } + } + } + ], + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + } + ] + } + } + }, + { + "description": "DeleteMany with hint document", + "operations": [ + { + "object": "collection", + "name": "deleteMany", + "arguments": { + "filter": { + "_id": { + "$gt": 1 + } + }, + "hint": { + "_id": 1 + } + }, + "result": { + "deletedCount": 2 + } + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "delete": "DeleteMany_hint", + "deletes": [ + { + "q": { + "_id": { + "$gt": 1 + } + }, + "hint": { + "_id": 1 + }, + "limit": 0 + } + ] + } + } + } + ], + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + } + ] + } + } + } + ] +} diff --git a/tests/SpecTests/crud/deleteOne-hint-clientError.json b/tests/SpecTests/crud/deleteOne-hint-clientError.json new file mode 100644 index 000000000..97f8ec492 --- /dev/null +++ b/tests/SpecTests/crud/deleteOne-hint-clientError.json @@ -0,0 +1,84 @@ +{ + "runOn": [ + { + "maxServerVersion": "3.3.99" + } + ], + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ], + "collection_name": "DeleteOne_hint", + "tests": [ + { + "description": "DeleteOne with hint string unsupported (client-side error)", + "operations": [ + { + "object": "collection", + "name": "deleteOne", + "arguments": { + "filter": { + "_id": 1 + }, + "hint": "_id_" + }, + "error": true + } + ], + "expectations": [], + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ] + } + } + }, + { + "description": "DeleteOne with hint document unsupported (client-side error)", + "operations": [ + { + "object": "collection", + "name": "deleteOne", + "arguments": { + "filter": { + "_id": 1 + }, + "hint": { + "_id": 1 + } + }, + "error": true + } + ], + "expectations": [], + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ] + } + } + } + ] +} diff --git a/tests/SpecTests/crud/deleteOne-hint-serverError.json b/tests/SpecTests/crud/deleteOne-hint-serverError.json new file mode 100644 index 000000000..3cf9400a8 --- /dev/null +++ b/tests/SpecTests/crud/deleteOne-hint-serverError.json @@ -0,0 +1,121 @@ +{ + "runOn": [ + { + "minServerVersion": "3.4.0", + "maxServerVersion": "4.3.3" + } + ], + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ], + "collection_name": "DeleteOne_hint", + "tests": [ + { + "description": "DeleteOne with hint string unsupported (server-side error)", + "operations": [ + { + "object": "collection", + "name": "deleteOne", + "arguments": { + "filter": { + "_id": 1 + }, + "hint": "_id_" + }, + "error": true + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "delete": "DeleteOne_hint", + "deletes": [ + { + "q": { + "_id": 1 + }, + "hint": "_id_", + "limit": 1 + } + ] + } + } + } + ], + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ] + } + } + }, + { + "description": "DeleteOne with hint document unsupported (server-side error)", + "operations": [ + { + "object": "collection", + "name": "deleteOne", + "arguments": { + "filter": { + "_id": 1 + }, + "hint": { + "_id": 1 + } + }, + "error": true + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "delete": "DeleteOne_hint", + "deletes": [ + { + "q": { + "_id": 1 + }, + "hint": { + "_id": 1 + }, + "limit": 1 + } + ] + } + } + } + ], + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ] + } + } + } + ] +} diff --git a/tests/SpecTests/crud/deleteOne-hint.json b/tests/SpecTests/crud/deleteOne-hint.json new file mode 100644 index 000000000..ec8e7715a --- /dev/null +++ b/tests/SpecTests/crud/deleteOne-hint.json @@ -0,0 +1,116 @@ +{ + "runOn": [ + { + "minServerVersion": "4.3.4" + } + ], + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ], + "collection_name": "DeleteOne_hint", + "tests": [ + { + "description": "DeleteOne with hint string", + "operations": [ + { + "object": "collection", + "name": "deleteOne", + "arguments": { + "filter": { + "_id": 1 + }, + "hint": "_id_" + }, + "result": { + "deletedCount": 1 + } + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "delete": "DeleteOne_hint", + "deletes": [ + { + "q": { + "_id": 1 + }, + "hint": "_id_", + "limit": 1 + } + ] + } + } + } + ], + "outcome": { + "collection": { + "data": [ + { + "_id": 2, + "x": 22 + } + ] + } + } + }, + { + "description": "deleteOne with hint document", + "operations": [ + { + "object": "collection", + "name": "deleteOne", + "arguments": { + "filter": { + "_id": 1 + }, + "hint": { + "_id": 1 + } + }, + "result": { + "deletedCount": 1 + } + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "delete": "DeleteOne_hint", + "deletes": [ + { + "q": { + "_id": 1 + }, + "hint": { + "_id": 1 + }, + "limit": 1 + } + ] + } + } + } + ], + "outcome": { + "collection": { + "data": [ + { + "_id": 2, + "x": 22 + } + ] + } + } + } + ] +} diff --git a/tests/SpecTests/crud/findOneAndDelete-hint-clientError.json b/tests/SpecTests/crud/findOneAndDelete-hint-clientError.json new file mode 100644 index 000000000..262e78ce7 --- /dev/null +++ b/tests/SpecTests/crud/findOneAndDelete-hint-clientError.json @@ -0,0 +1,84 @@ +{ + "runOn": [ + { + "maxServerVersion": "4.0.99" + } + ], + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ], + "collection_name": "findOneAndDelete_hint", + "tests": [ + { + "description": "FindOneAndDelete with hint string unsupported (client-side error)", + "operations": [ + { + "object": "collection", + "name": "findOneAndDelete", + "arguments": { + "filter": { + "_id": 1 + }, + "hint": "_id_" + }, + "error": true + } + ], + "expectations": [], + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ] + } + } + }, + { + "description": "FindOneAndDelete with hint document", + "operations": [ + { + "object": "collection", + "name": "findOneAndDelete", + "arguments": { + "filter": { + "_id": 1 + }, + "hint": { + "_id": 1 + } + }, + "error": true + } + ], + "expectations": [], + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ] + } + } + } + ] +} diff --git a/tests/SpecTests/crud/findOneAndDelete-hint-serverError.json b/tests/SpecTests/crud/findOneAndDelete-hint-serverError.json new file mode 100644 index 000000000..9412b36f2 --- /dev/null +++ b/tests/SpecTests/crud/findOneAndDelete-hint-serverError.json @@ -0,0 +1,113 @@ +{ + "runOn": [ + { + "minServerVersion": "4.2.0", + "maxServerVersion": "4.3.3" + } + ], + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ], + "collection_name": "findOneAndDelete_hint", + "tests": [ + { + "description": "FindOneAndDelete with hint string unsupported (server-side error)", + "operations": [ + { + "object": "collection", + "name": "findOneAndDelete", + "arguments": { + "filter": { + "_id": 1 + }, + "hint": "_id_" + }, + "error": true + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "findAndModify": "findOneAndDelete_hint", + "query": { + "_id": 1 + }, + "hint": "_id_", + "remove": true + } + } + } + ], + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ] + } + } + }, + { + "description": "FindOneAndDelete with hint document unsupported (server-side error)", + "operations": [ + { + "object": "collection", + "name": "findOneAndDelete", + "arguments": { + "filter": { + "_id": 1 + }, + "hint": { + "_id": 1 + } + }, + "error": true + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "findAndModify": "findOneAndDelete_hint", + "query": { + "_id": 1 + }, + "hint": { + "_id": 1 + }, + "remove": true + } + } + } + ], + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ] + } + } + } + ] +} diff --git a/tests/SpecTests/crud/findOneAndDelete-hint.json b/tests/SpecTests/crud/findOneAndDelete-hint.json new file mode 100644 index 000000000..fe8dcfa4c --- /dev/null +++ b/tests/SpecTests/crud/findOneAndDelete-hint.json @@ -0,0 +1,110 @@ +{ + "runOn": [ + { + "minServerVersion": "4.3.4" + } + ], + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ], + "collection_name": "findOneAndDelete_hint", + "tests": [ + { + "description": "FindOneAndDelete with hint string", + "operations": [ + { + "object": "collection", + "name": "findOneAndDelete", + "arguments": { + "filter": { + "_id": 1 + }, + "hint": "_id_" + }, + "result": { + "_id": 1, + "x": 11 + } + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "findAndModify": "findOneAndDelete_hint", + "query": { + "_id": 1 + }, + "hint": "_id_", + "remove": true + } + } + } + ], + "outcome": { + "collection": { + "data": [ + { + "_id": 2, + "x": 22 + } + ] + } + } + }, + { + "description": "FindOneAndDelete with hint document", + "operations": [ + { + "object": "collection", + "name": "findOneAndDelete", + "arguments": { + "filter": { + "_id": 1 + }, + "hint": { + "_id": 1 + } + }, + "result": { + "_id": 1, + "x": 11 + } + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "findAndModify": "findOneAndDelete_hint", + "query": { + "_id": 1 + }, + "hint": { + "_id": 1 + }, + "remove": true + } + } + } + ], + "outcome": { + "collection": { + "data": [ + { + "_id": 2, + "x": 22 + } + ] + } + } + } + ] +} diff --git a/tests/SpecTests/crud/unacknowledged-bulkWrite-delete-hint-clientError.json b/tests/SpecTests/crud/unacknowledged-bulkWrite-delete-hint-clientError.json new file mode 100644 index 000000000..a92c5dfb8 --- /dev/null +++ b/tests/SpecTests/crud/unacknowledged-bulkWrite-delete-hint-clientError.json @@ -0,0 +1,160 @@ +{ + "runOn": [ + { + "maxServerVersion": "4.3.3" + } + ], + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + }, + { + "_id": 4, + "x": 44 + } + ], + "collection_name": "BulkWrite_delete_hint", + "tests": [ + { + "description": "Unacknowledged bulkWrite deleteOne with hints fails with client-side error on server < 4.4", + "operations": [ + { + "name": "bulkWrite", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + }, + "arguments": { + "requests": [ + { + "name": "deleteOne", + "arguments": { + "filter": { + "_id": 1 + }, + "hint": "_id_" + } + }, + { + "name": "deleteOne", + "arguments": { + "filter": { + "_id": 2 + }, + "hint": { + "_id": 1 + } + } + } + ], + "options": { + "ordered": true + } + }, + "error": true + } + ], + "expectations": {}, + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + }, + { + "_id": 4, + "x": 44 + } + ] + } + } + }, + { + "description": "Unacknowledged bulkWrite deleteMany with hints fails with client-side error on server < 4.4", + "operations": [ + { + "name": "bulkWrite", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + }, + "arguments": { + "requests": [ + { + "name": "deleteMany", + "arguments": { + "filter": { + "_id": { + "$lt": 3 + } + }, + "hint": "_id_" + } + }, + { + "name": "deleteMany", + "arguments": { + "filter": { + "_id": { + "$gte": 4 + } + }, + "hint": { + "_id": 1 + } + } + } + ], + "options": { + "ordered": true + } + }, + "error": true + } + ], + "expectations": {}, + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + }, + { + "_id": 4, + "x": 44 + } + ] + } + } + } + ] +} diff --git a/tests/SpecTests/crud/unacknowledged-bulkWrite-delete-hint.json b/tests/SpecTests/crud/unacknowledged-bulkWrite-delete-hint.json new file mode 100644 index 000000000..b2147a27f --- /dev/null +++ b/tests/SpecTests/crud/unacknowledged-bulkWrite-delete-hint.json @@ -0,0 +1,174 @@ +{ + "runOn": [ + { + "minServerVersion": "4.3.4" + } + ], + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + }, + { + "_id": 4, + "x": 44 + } + ], + "collection_name": "BulkWrite_delete_hint", + "tests": [ + { + "description": "Unacknowledged bulkWrite deleteOne with hints succeeds on server >= 4.4", + "operations": [ + { + "name": "bulkWrite", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + }, + "arguments": { + "requests": [ + { + "name": "deleteOne", + "arguments": { + "filter": { + "_id": 1 + }, + "hint": "_id_" + } + }, + { + "name": "deleteOne", + "arguments": { + "filter": { + "_id": 2 + }, + "hint": { + "_id": 1 + } + } + } + ], + "options": { + "ordered": true + } + } + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "delete": "BulkWrite_delete_hint", + "deletes": [ + { + "q": { + "_id": 1 + }, + "hint": "_id_", + "limit": 1 + }, + { + "q": { + "_id": 2 + }, + "hint": { + "_id": 1 + }, + "limit": 1 + } + ], + "ordered": true + } + } + } + ], + "outcome": {} + }, + { + "description": "Unacknowledged bulkWrite deleteMany with hints succeeds on server >= 4.4", + "operations": [ + { + "name": "bulkWrite", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + }, + "arguments": { + "requests": [ + { + "name": "deleteMany", + "arguments": { + "filter": { + "_id": { + "$lt": 3 + } + }, + "hint": "_id_" + } + }, + { + "name": "deleteMany", + "arguments": { + "filter": { + "_id": { + "$gte": 4 + } + }, + "hint": { + "_id": 1 + } + } + } + ], + "options": { + "ordered": true + } + } + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "delete": "BulkWrite_delete_hint", + "deletes": [ + { + "q": { + "_id": { + "$lt": 3 + } + }, + "hint": "_id_", + "limit": 0 + }, + { + "q": { + "_id": { + "$gte": 4 + } + }, + "hint": { + "_id": 1 + }, + "limit": 0 + } + ], + "ordered": true + } + } + } + ], + "outcome": {} + } + ] +} diff --git a/tests/SpecTests/crud/unacknowledged-bulkWrite-update-hint-clientError.json b/tests/SpecTests/crud/unacknowledged-bulkWrite-update-hint-clientError.json new file mode 100644 index 000000000..93c46f82e --- /dev/null +++ b/tests/SpecTests/crud/unacknowledged-bulkWrite-update-hint-clientError.json @@ -0,0 +1,250 @@ +{ + "runOn": [ + { + "maxServerVersion": "4.1.9" + } + ], + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + }, + { + "_id": 4, + "x": 44 + } + ], + "collection_name": "Bulkwrite_update_hint", + "tests": [ + { + "description": "Unacknowledged bulkWrite updateOne with hints fails with client-side error on server < 4.2", + "operations": [ + { + "name": "bulkWrite", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + }, + "arguments": { + "requests": [ + { + "name": "updateOne", + "arguments": { + "filter": { + "_id": 1 + }, + "update": { + "$inc": { + "x": 1 + } + }, + "hint": "_id_" + } + }, + { + "name": "updateOne", + "arguments": { + "filter": { + "_id": 1 + }, + "update": { + "$inc": { + "x": 1 + } + }, + "hint": { + "_id": 1 + } + } + } + ], + "options": { + "ordered": true + } + }, + "error": true + } + ], + "expectations": {}, + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + }, + { + "_id": 4, + "x": 44 + } + ] + } + } + }, + { + "description": "Unacknowledged bulkWrite updateMany with hints fails with client-side error on server < 4.2", + "operations": [ + { + "name": "bulkWrite", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + }, + "arguments": { + "requests": [ + { + "name": "updateMany", + "arguments": { + "filter": { + "_id": { + "$lt": 3 + } + }, + "update": { + "$inc": { + "x": 1 + } + }, + "hint": "_id_" + } + }, + { + "name": "updateMany", + "arguments": { + "filter": { + "_id": { + "$lt": 3 + } + }, + "update": { + "$inc": { + "x": 1 + } + }, + "hint": { + "_id": 1 + } + } + } + ], + "options": { + "ordered": true + } + }, + "error": true + } + ], + "expectations": {}, + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + }, + { + "_id": 4, + "x": 44 + } + ] + } + } + }, + { + "description": "Unacknowledged bulkWrite replaceOne with hints unsupported (client-side error)", + "operations": [ + { + "name": "bulkWrite", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + }, + "arguments": { + "requests": [ + { + "name": "replaceOne", + "arguments": { + "filter": { + "_id": 3 + }, + "replacement": { + "x": 333 + }, + "hint": "_id_" + } + }, + { + "name": "replaceOne", + "arguments": { + "filter": { + "_id": 4 + }, + "replacement": { + "x": 444 + }, + "hint": { + "_id": 1 + } + } + } + ], + "options": { + "ordered": true + } + }, + "error": true + } + ], + "expectations": {}, + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + }, + { + "_id": 4, + "x": 44 + } + ] + } + } + } + ] +} diff --git a/tests/SpecTests/crud/unacknowledged-bulkWrite-update-hint.json b/tests/SpecTests/crud/unacknowledged-bulkWrite-update-hint.json new file mode 100644 index 000000000..eaba364e9 --- /dev/null +++ b/tests/SpecTests/crud/unacknowledged-bulkWrite-update-hint.json @@ -0,0 +1,291 @@ +{ + "runOn": [ + { + "minServerVersion": "4.2.0" + } + ], + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + }, + { + "_id": 4, + "x": 44 + } + ], + "collection_name": "BulkWrite_update_hint", + "tests": [ + { + "description": "Unacknowledged bulkWrite updateOne with update hint succeeds on server >= 4.2", + "operations": [ + { + "name": "bulkWrite", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + }, + "arguments": { + "requests": [ + { + "name": "updateOne", + "arguments": { + "filter": { + "_id": 1 + }, + "update": { + "$inc": { + "x": 1 + } + }, + "hint": "_id_" + } + }, + { + "name": "updateOne", + "arguments": { + "filter": { + "_id": 1 + }, + "update": { + "$inc": { + "x": 1 + } + }, + "hint": { + "_id": 1 + } + } + } + ], + "options": { + "ordered": true + } + } + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "update": "BulkWrite_update_hint", + "updates": [ + { + "q": { + "_id": 1 + }, + "u": { + "$inc": { + "x": 1 + } + }, + "hint": "_id_" + }, + { + "q": { + "_id": 1 + }, + "u": { + "$inc": { + "x": 1 + } + }, + "hint": { + "_id": 1 + } + } + ], + "ordered": true + } + } + } + ], + "outcome": {} + }, + { + "description": "Unacknowledged bulkWrite updateMany with update hint succeeds on server >= 4.2", + "operations": [ + { + "name": "bulkWrite", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + }, + "arguments": { + "requests": [ + { + "name": "updateMany", + "arguments": { + "filter": { + "_id": { + "$lt": 3 + } + }, + "update": { + "$inc": { + "x": 1 + } + }, + "hint": "_id_" + } + }, + { + "name": "updateMany", + "arguments": { + "filter": { + "_id": { + "$lt": 3 + } + }, + "update": { + "$inc": { + "x": 1 + } + }, + "hint": { + "_id": 1 + } + } + } + ], + "options": { + "ordered": true + } + } + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "update": "BulkWrite_update_hint", + "updates": [ + { + "q": { + "_id": { + "$lt": 3 + } + }, + "u": { + "$inc": { + "x": 1 + } + }, + "multi": true, + "hint": "_id_" + }, + { + "q": { + "_id": { + "$lt": 3 + } + }, + "u": { + "$inc": { + "x": 1 + } + }, + "multi": true, + "hint": { + "_id": 1 + } + } + ], + "ordered": true + } + } + } + ], + "outcome": {} + }, + { + "description": "Unacknowledged bulkWrite replaceOne with update hints", + "operations": [ + { + "name": "bulkWrite", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + }, + "arguments": { + "requests": [ + { + "name": "replaceOne", + "arguments": { + "filter": { + "_id": 3 + }, + "replacement": { + "x": 333 + }, + "hint": "_id_" + } + }, + { + "name": "replaceOne", + "arguments": { + "filter": { + "_id": 4 + }, + "replacement": { + "x": 444 + }, + "hint": { + "_id": 1 + } + } + } + ], + "options": { + "ordered": true + } + } + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "update": "BulkWrite_update_hint", + "updates": [ + { + "q": { + "_id": 3 + }, + "u": { + "x": 333 + }, + "hint": "_id_" + }, + { + "q": { + "_id": 4 + }, + "u": { + "x": 444 + }, + "hint": { + "_id": 1 + } + } + ], + "ordered": true + } + } + } + ], + "outcome": {} + } + ] +} diff --git a/tests/SpecTests/crud/unacknowledged-deleteMany-hint-clientError.json b/tests/SpecTests/crud/unacknowledged-deleteMany-hint-clientError.json new file mode 100644 index 000000000..903340bf0 --- /dev/null +++ b/tests/SpecTests/crud/unacknowledged-deleteMany-hint-clientError.json @@ -0,0 +1,110 @@ +{ + "runOn": [ + { + "maxServerVersion": "4.3.3" + } + ], + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + } + ], + "collection_name": "DeleteMany_hint", + "tests": [ + { + "description": "Unacknowledged deleteMany with hint string fails with client-side error on server < 4.4", + "operations": [ + { + "object": "collection", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + }, + "name": "deleteMany", + "arguments": { + "filter": { + "_id": { + "$gt": 1 + } + }, + "hint": "_id_" + }, + "error": true + } + ], + "expectations": {}, + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + } + ] + } + } + }, + { + "description": "Unacknowledged deleteMany with hint document fails with client-side error on server < 4.4", + "operations": [ + { + "object": "collection", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + }, + "name": "deleteMany", + "arguments": { + "filter": { + "_id": { + "$gt": 1 + } + }, + "hint": { + "_id": 1 + } + }, + "error": true + } + ], + "expectations": {}, + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + } + ] + } + } + } + ] +} diff --git a/tests/SpecTests/crud/unacknowledged-deleteMany-hint.json b/tests/SpecTests/crud/unacknowledged-deleteMany-hint.json new file mode 100644 index 000000000..485fd6198 --- /dev/null +++ b/tests/SpecTests/crud/unacknowledged-deleteMany-hint.json @@ -0,0 +1,114 @@ +{ + "runOn": [ + { + "minServerVersion": "4.3.4" + } + ], + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + } + ], + "collection_name": "DeleteMany_hint", + "tests": [ + { + "description": "Unacknowledged deleteMany with hint string succeeds on server >= 4.4", + "operations": [ + { + "object": "collection", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + }, + "name": "deleteMany", + "arguments": { + "filter": { + "_id": { + "$gt": 1 + } + }, + "hint": "_id_" + } + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "delete": "DeleteMany_hint", + "deletes": [ + { + "q": { + "_id": { + "$gt": 1 + } + }, + "hint": "_id_", + "limit": 0 + } + ] + } + } + } + ], + "outcome": {} + }, + { + "description": "Unacknowledged deleteMany with hint document succeeds on server >= 4.4", + "operations": [ + { + "object": "collection", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + }, + "name": "deleteMany", + "arguments": { + "filter": { + "_id": { + "$gt": 1 + } + }, + "hint": { + "_id": 1 + } + } + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "delete": "DeleteMany_hint", + "deletes": [ + { + "q": { + "_id": { + "$gt": 1 + } + }, + "hint": { + "_id": 1 + }, + "limit": 0 + } + ] + } + } + } + ], + "outcome": {} + } + ] +} diff --git a/tests/SpecTests/crud/unacknowledged-deleteOne-hint-clientError.json b/tests/SpecTests/crud/unacknowledged-deleteOne-hint-clientError.json new file mode 100644 index 000000000..11e0b883c --- /dev/null +++ b/tests/SpecTests/crud/unacknowledged-deleteOne-hint-clientError.json @@ -0,0 +1,94 @@ +{ + "runOn": [ + { + "maxServerVersion": "4.3.3" + } + ], + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ], + "collection_name": "DeleteOne_hint", + "tests": [ + { + "description": "Unacknowledged deleteOne with hint string fails with client-side error on server < 4.4", + "operations": [ + { + "object": "collection", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + }, + "name": "deleteOne", + "arguments": { + "filter": { + "_id": 1 + }, + "hint": "_id_" + }, + "error": true + } + ], + "expectations": {}, + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ] + } + } + }, + { + "description": "Unacknowledged deleteOne with hint document fails with client-side error on server < 4.4", + "operations": [ + { + "object": "collection", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + }, + "name": "deleteOne", + "arguments": { + "filter": { + "_id": 1 + }, + "hint": { + "_id": 1 + } + }, + "error": true + } + ], + "expectations": {}, + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ] + } + } + } + ] +} diff --git a/tests/SpecTests/crud/unacknowledged-deleteOne-hint.json b/tests/SpecTests/crud/unacknowledged-deleteOne-hint.json new file mode 100644 index 000000000..bd9443d4f --- /dev/null +++ b/tests/SpecTests/crud/unacknowledged-deleteOne-hint.json @@ -0,0 +1,102 @@ +{ + "runOn": [ + { + "minServerVersion": "4.3.4" + } + ], + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ], + "collection_name": "DeleteOne_hint", + "tests": [ + { + "description": "Unacknowledged deleteOne with hint string succeeds on server >= 4.4", + "operations": [ + { + "object": "collection", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + }, + "name": "deleteOne", + "arguments": { + "filter": { + "_id": 1 + }, + "hint": "_id_" + } + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "delete": "DeleteOne_hint", + "deletes": [ + { + "q": { + "_id": 1 + }, + "hint": "_id_", + "limit": 1 + } + ] + } + } + } + ], + "outcome": {} + }, + { + "description": "Unacknowledged deleteOne with hint document succeeds on server >= 4.4", + "operations": [ + { + "object": "collection", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + }, + "name": "deleteOne", + "arguments": { + "filter": { + "_id": 1 + }, + "hint": { + "_id": 1 + } + } + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "delete": "DeleteOne_hint", + "deletes": [ + { + "q": { + "_id": 1 + }, + "hint": { + "_id": 1 + }, + "limit": 1 + } + ] + } + } + } + ], + "outcome": {} + } + ] +} diff --git a/tests/SpecTests/crud/unacknowledged-findOneAndDelete-hint-clientError.json b/tests/SpecTests/crud/unacknowledged-findOneAndDelete-hint-clientError.json new file mode 100644 index 000000000..1c4423d3c --- /dev/null +++ b/tests/SpecTests/crud/unacknowledged-findOneAndDelete-hint-clientError.json @@ -0,0 +1,94 @@ +{ + "runOn": [ + { + "maxServerVersion": "4.3.3" + } + ], + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ], + "collection_name": "findOneAndDelete_hint", + "tests": [ + { + "description": "Unacknowledged findOneAndDelete with hint string fails with client-side error on server < 4.4", + "operations": [ + { + "object": "collection", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + }, + "name": "findOneAndDelete", + "arguments": { + "filter": { + "_id": 1 + }, + "hint": "_id_" + }, + "error": true + } + ], + "expectations": {}, + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ] + } + } + }, + { + "description": "Unacknowledged findOneAndDelete with hint document fails with client-side error on server < 4.4", + "operations": [ + { + "object": "collection", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + }, + "name": "findOneAndDelete", + "arguments": { + "filter": { + "_id": 1 + }, + "hint": { + "_id": 1 + } + }, + "error": true + } + ], + "expectations": {}, + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ] + } + } + } + ] +} diff --git a/tests/SpecTests/crud/unacknowledged-findOneAndDelete-hint.json b/tests/SpecTests/crud/unacknowledged-findOneAndDelete-hint.json new file mode 100644 index 000000000..9dce1ae9d --- /dev/null +++ b/tests/SpecTests/crud/unacknowledged-findOneAndDelete-hint.json @@ -0,0 +1,94 @@ +{ + "runOn": [ + { + "minServerVersion": "4.3.4" + } + ], + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ], + "collection_name": "findOneAndDelete_hint", + "tests": [ + { + "description": "Unacknowledged findOneAndDelete with hint string succeeds on server >= 4.4", + "operations": [ + { + "object": "collection", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + }, + "name": "findOneAndDelete", + "arguments": { + "filter": { + "_id": 1 + }, + "hint": "_id_" + } + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "findAndModify": "findOneAndDelete_hint", + "query": { + "_id": 1 + }, + "hint": "_id_", + "remove": true + } + } + } + ], + "outcome": {} + }, + { + "description": "Unacknowledged findOneAndDelete with hint document succeeds on server >= 4.4", + "operations": [ + { + "object": "collection", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + }, + "name": "findOneAndDelete", + "arguments": { + "filter": { + "_id": 1 + }, + "hint": { + "_id": 1 + } + } + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "findAndModify": "findOneAndDelete_hint", + "query": { + "_id": 1 + }, + "hint": { + "_id": 1 + }, + "remove": true + } + } + } + ], + "outcome": {} + } + ] +} diff --git a/tests/SpecTests/crud/unacknowledged-findOneAndReplace-hint-clientError.json b/tests/SpecTests/crud/unacknowledged-findOneAndReplace-hint-clientError.json new file mode 100644 index 000000000..0379e7946 --- /dev/null +++ b/tests/SpecTests/crud/unacknowledged-findOneAndReplace-hint-clientError.json @@ -0,0 +1,100 @@ +{ + "runOn": [ + { + "maxServerVersion": "4.3.3" + } + ], + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ], + "collection_name": "FindOneAndReplace_hint", + "tests": [ + { + "description": "Unacknowledged findOneAndReplace with hint string fails with client-side error on server < 4.4", + "operations": [ + { + "object": "collection", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + }, + "name": "findOneAndReplace", + "arguments": { + "filter": { + "_id": 1 + }, + "replacement": { + "x": 33 + }, + "hint": "_id_" + }, + "error": true + } + ], + "expectations": {}, + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ] + } + } + }, + { + "description": "Unacknowledged findOneAndReplace with hint document fails with client-side error on server < 4.4", + "operations": [ + { + "object": "collection", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + }, + "name": "findOneAndReplace", + "arguments": { + "filter": { + "_id": 1 + }, + "replacement": { + "x": 33 + }, + "hint": { + "_id": 1 + } + }, + "error": true + } + ], + "expectations": {}, + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ] + } + } + } + ] +} diff --git a/tests/SpecTests/crud/unacknowledged-findOneAndReplace-hint.json b/tests/SpecTests/crud/unacknowledged-findOneAndReplace-hint.json new file mode 100644 index 000000000..7c3e55e04 --- /dev/null +++ b/tests/SpecTests/crud/unacknowledged-findOneAndReplace-hint.json @@ -0,0 +1,101 @@ +{ + "runOn": [ + { + "minServerVersion": "4.3.4" + } + ], + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ], + "collection_name": "FindOneAndReplace_hint", + "tests": [ + { + "description": "Unacknowledged findOneAndReplace with hint string succeeds on server >= 4.4", + "operations": [ + { + "object": "collection", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + }, + "name": "findOneAndReplace", + "arguments": { + "filter": { + "_id": 1 + }, + "replacement": { + "x": 33 + }, + "hint": "_id_" + } + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "findAndModify": "FindOneAndReplace_hint", + "query": { + "_id": 1 + }, + "update": { + "x": 33 + }, + "hint": "_id_" + } + } + } + ], + "outcome": {} + }, + { + "description": "Unacknowledged findOneAndReplace with hint document succeeds on server >= 4.4", + "operations": [ + { + "object": "collection", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + }, + "name": "findOneAndReplace", + "arguments": { + "filter": { + "_id": 1 + }, + "replacement": { + "x": 33 + }, + "hint": { + "_id": 1 + } + } + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "findAndModify": "FindOneAndReplace_hint", + "query": { + "_id": 1 + }, + "update": { + "x": 33 + } + } + } + } + ], + "outcome": {} + } + ] +} diff --git a/tests/SpecTests/crud/unacknowledged-findOneAndUpdate-hint-clientError.json b/tests/SpecTests/crud/unacknowledged-findOneAndUpdate-hint-clientError.json new file mode 100644 index 000000000..14e1fb6da --- /dev/null +++ b/tests/SpecTests/crud/unacknowledged-findOneAndUpdate-hint-clientError.json @@ -0,0 +1,104 @@ +{ + "runOn": [ + { + "maxServerVersion": "4.3.3" + } + ], + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ], + "collection_name": "FindOneAndUpdate_hint", + "tests": [ + { + "description": "Unacknowledged findOneAndUpdate with hint string fails with client-side error on server < 4.4", + "operations": [ + { + "object": "collection", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + }, + "name": "findOneAndUpdate", + "arguments": { + "filter": { + "_id": 1 + }, + "update": { + "$inc": { + "x": 1 + } + }, + "hint": "_id_" + }, + "error": true + } + ], + "expectations": {}, + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ] + } + } + }, + { + "description": "Unacknowledged findOneAndUpdate with hint document fails with client-side error on server < 4.4", + "operations": [ + { + "object": "collection", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + }, + "name": "findOneAndUpdate", + "arguments": { + "filter": { + "_id": 1 + }, + "update": { + "$inc": { + "x": 1 + } + }, + "hint": { + "_id": 1 + } + }, + "error": true + } + ], + "expectations": {}, + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ] + } + } + } + ] +} diff --git a/tests/SpecTests/crud/unacknowledged-findOneAndUpdate-hint.json b/tests/SpecTests/crud/unacknowledged-findOneAndUpdate-hint.json new file mode 100644 index 000000000..383ca6ad6 --- /dev/null +++ b/tests/SpecTests/crud/unacknowledged-findOneAndUpdate-hint.json @@ -0,0 +1,112 @@ +{ + "runOn": [ + { + "minServerVersion": "4.3.4" + } + ], + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ], + "collection_name": "FindOneAndUpdate_hint", + "tests": [ + { + "description": "Unacknowledged findOneAndUpdate with hint string succeeds on server >= 4.4", + "operations": [ + { + "object": "collection", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + }, + "name": "findOneAndUpdate", + "arguments": { + "filter": { + "_id": 1 + }, + "update": { + "$inc": { + "x": 1 + } + }, + "hint": "_id_" + } + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "findAndModify": "FindOneAndUpdate_hint", + "query": { + "_id": 1 + }, + "update": { + "$inc": { + "x": 1 + } + }, + "hint": "_id_" + } + } + } + ], + "outcome": {} + }, + { + "description": "Unacknowledged findOneAndUpdate with hint document succeeds on server >= 4.4", + "operations": [ + { + "object": "collection", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + }, + "name": "findOneAndUpdate", + "arguments": { + "filter": { + "_id": 1 + }, + "update": { + "$inc": { + "x": 1 + } + }, + "hint": { + "_id": 1 + } + } + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "findAndModify": "FindOneAndUpdate_hint", + "query": { + "_id": 1 + }, + "update": { + "$inc": { + "x": 1 + } + }, + "hint": { + "_id": 1 + } + } + } + } + ], + "outcome": {} + } + ] +} diff --git a/tests/SpecTests/crud/unacknowledged-replaceOne-hint-clientError.json b/tests/SpecTests/crud/unacknowledged-replaceOne-hint-clientError.json new file mode 100644 index 000000000..f442953f2 --- /dev/null +++ b/tests/SpecTests/crud/unacknowledged-replaceOne-hint-clientError.json @@ -0,0 +1,104 @@ +{ + "runOn": [ + { + "maxServerVersion": "4.1.9" + } + ], + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ], + "collection_name": "ReplaceOne_hint", + "tests": [ + { + "description": "Unacknowledged ReplaceOne with hint string fails with client-side error on server < 4.2", + "operations": [ + { + "object": "collection", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + }, + "name": "replaceOne", + "arguments": { + "filter": { + "_id": { + "$gt": 1 + } + }, + "replacement": { + "x": 111 + }, + "hint": "_id_" + }, + "error": true + } + ], + "expectations": {}, + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ] + } + } + }, + { + "description": "Unacknowledged ReplaceOne with hint document fails with client-side error on server < 4.2", + "operations": [ + { + "object": "collection", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + }, + "name": "replaceOne", + "arguments": { + "filter": { + "_id": { + "$gt": 1 + } + }, + "replacement": { + "x": 111 + }, + "hint": { + "_id": 1 + } + }, + "error": true + } + ], + "expectations": {}, + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ] + } + } + } + ] +} diff --git a/tests/SpecTests/crud/unacknowledged-replaceOne-hint.json b/tests/SpecTests/crud/unacknowledged-replaceOne-hint.json new file mode 100644 index 000000000..1d896bfb5 --- /dev/null +++ b/tests/SpecTests/crud/unacknowledged-replaceOne-hint.json @@ -0,0 +1,120 @@ +{ + "runOn": [ + { + "minServerVersion": "4.2.0" + } + ], + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ], + "collection_name": "Replaceone_hint", + "tests": [ + { + "description": "Unacknowledged replaceOne with hint string succeeds on server >= 4.2", + "operations": [ + { + "object": "collection", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + }, + "name": "replaceOne", + "arguments": { + "filter": { + "_id": { + "$gt": 1 + } + }, + "replacement": { + "x": 111 + }, + "hint": "_id_" + } + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "update": "Replaceone_hint", + "updates": [ + { + "q": { + "_id": { + "$gt": 1 + } + }, + "u": { + "x": 111 + }, + "hint": "_id_" + } + ] + } + } + } + ], + "outcome": {} + }, + { + "description": "Unacknowledged replaceOne with hint document succeeds on server >= 4.2", + "operations": [ + { + "object": "collection", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + }, + "name": "replaceOne", + "arguments": { + "filter": { + "_id": { + "$gt": 1 + } + }, + "replacement": { + "x": 111 + }, + "hint": { + "_id": 1 + } + } + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "update": "Replaceone_hint", + "updates": [ + { + "q": { + "_id": { + "$gt": 1 + } + }, + "u": { + "x": 111 + }, + "hint": { + "_id": 1 + } + } + ] + } + } + } + ], + "outcome": {} + } + ] +} diff --git a/tests/SpecTests/crud/unacknowledged-updateMany-hint-clientError.json b/tests/SpecTests/crud/unacknowledged-updateMany-hint-clientError.json new file mode 100644 index 000000000..9425d542e --- /dev/null +++ b/tests/SpecTests/crud/unacknowledged-updateMany-hint-clientError.json @@ -0,0 +1,120 @@ +{ + "runOn": [ + { + "maxServerVersion": "4.1.9" + } + ], + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + } + ], + "collection_name": "Updatemany_hint", + "tests": [ + { + "description": "Unacknowledged updateMany with hint string fails with client-side error on server < 4.2", + "operations": [ + { + "object": "collection", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + }, + "name": "updateMany", + "arguments": { + "filter": { + "_id": { + "$gt": 1 + } + }, + "update": { + "$inc": { + "x": 1 + } + }, + "hint": "_id_" + }, + "error": true + } + ], + "expectations": {}, + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + } + ] + } + } + }, + { + "description": "Unacknowledged updateMany with hint document fails with client-side error on server < 4.2", + "operations": [ + { + "object": "collection", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + }, + "name": "updateMany", + "arguments": { + "filter": { + "_id": { + "$gt": 1 + } + }, + "update": { + "$inc": { + "x": 1 + } + }, + "hint": { + "_id": 1 + } + }, + "error": true + } + ], + "expectations": {}, + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + } + ] + } + } + } + ] +} diff --git a/tests/SpecTests/crud/unacknowledged-updateMany-hint.json b/tests/SpecTests/crud/unacknowledged-updateMany-hint.json new file mode 100644 index 000000000..d601a1b70 --- /dev/null +++ b/tests/SpecTests/crud/unacknowledged-updateMany-hint.json @@ -0,0 +1,134 @@ +{ + "runOn": [ + { + "minServerVersion": "4.2.0" + } + ], + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + } + ], + "collection_name": "UpdateMany_hint", + "tests": [ + { + "description": "Unacknowledged updateMany with hint string succeeds on server >= 4.2", + "operations": [ + { + "object": "collection", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + }, + "name": "updateMany", + "arguments": { + "filter": { + "_id": { + "$gt": 1 + } + }, + "update": { + "$inc": { + "x": 1 + } + }, + "hint": "_id_" + } + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "update": "UpdateMany_hint", + "updates": [ + { + "q": { + "_id": { + "$gt": 1 + } + }, + "u": { + "$inc": { + "x": 1 + } + }, + "multi": true, + "hint": "_id_" + } + ] + } + } + } + ], + "outcome": {} + }, + { + "description": "Unacknowledged updateMany with hint document succeeds on server >= 4.2", + "operations": [ + { + "object": "collection", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + }, + "name": "updateMany", + "arguments": { + "filter": { + "_id": { + "$gt": 1 + } + }, + "update": { + "$inc": { + "x": 1 + } + }, + "hint": { + "_id": 1 + } + } + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "update": "UpdateMany_hint", + "updates": [ + { + "q": { + "_id": { + "$gt": 1 + } + }, + "u": { + "$inc": { + "x": 1 + } + }, + "multi": true, + "hint": { + "_id": 1 + } + } + ] + } + } + } + ], + "outcome": {} + } + ] +} diff --git a/tests/SpecTests/crud/unacknowledged-updateOne-hint-clientError.json b/tests/SpecTests/crud/unacknowledged-updateOne-hint-clientError.json new file mode 100644 index 000000000..bce3add67 --- /dev/null +++ b/tests/SpecTests/crud/unacknowledged-updateOne-hint-clientError.json @@ -0,0 +1,108 @@ +{ + "runOn": [ + { + "maxServerVersion": "4.1.9" + } + ], + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ], + "collection_name": "Updateone_hint", + "tests": [ + { + "description": "Unacknowledged updateOne with hint string fails with client-side error on server < 4.2", + "operations": [ + { + "object": "collection", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + }, + "name": "updateOne", + "arguments": { + "filter": { + "_id": { + "$gt": 1 + } + }, + "update": { + "$inc": { + "x": 1 + } + }, + "hint": "_id_" + }, + "error": true + } + ], + "expectations": {}, + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ] + } + } + }, + { + "description": "Unacknowledged updateOne with hint document fails with client-side error on server < 4.2", + "operations": [ + { + "object": "collection", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + }, + "name": "updateOne", + "arguments": { + "filter": { + "_id": { + "$gt": 1 + } + }, + "update": { + "$inc": { + "x": 1 + } + }, + "hint": { + "_id": 1 + } + }, + "error": true + } + ], + "expectations": {}, + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ] + } + } + } + ] +} diff --git a/tests/SpecTests/crud/unacknowledged-updateOne-hint.json b/tests/SpecTests/crud/unacknowledged-updateOne-hint.json new file mode 100644 index 000000000..ca2f57f62 --- /dev/null +++ b/tests/SpecTests/crud/unacknowledged-updateOne-hint.json @@ -0,0 +1,128 @@ +{ + "runOn": [ + { + "minServerVersion": "4.2.0" + } + ], + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ], + "collection_name": "updateone_hint", + "tests": [ + { + "description": "Unacknowledged updateOne with hint string succeeds on server >= 4.2", + "operations": [ + { + "object": "collection", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + }, + "name": "updateOne", + "arguments": { + "filter": { + "_id": { + "$gt": 1 + } + }, + "update": { + "$inc": { + "x": 1 + } + }, + "hint": "_id_" + } + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "update": "updateone_hint", + "updates": [ + { + "q": { + "_id": { + "$gt": 1 + } + }, + "u": { + "$inc": { + "x": 1 + } + }, + "hint": "_id_" + } + ] + } + } + } + ], + "outcome": {} + }, + { + "description": "Unacknowledged updateOne with hint document succeeds on server >= 4.2", + "operations": [ + { + "object": "collection", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + }, + "name": "updateOne", + "arguments": { + "filter": { + "_id": { + "$gt": 1 + } + }, + "update": { + "$inc": { + "x": 1 + } + }, + "hint": { + "_id": 1 + } + } + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "update": "updateone_hint", + "updates": [ + { + "q": { + "_id": { + "$gt": 1 + } + }, + "u": { + "$inc": { + "x": 1 + } + }, + "hint": { + "_id": 1 + } + } + ] + } + } + } + ], + "outcome": {} + } + ] +} diff --git a/tests/SpecTests/crud/updateMany-hint-clientError.json b/tests/SpecTests/crud/updateMany-hint-clientError.json new file mode 100644 index 000000000..44ebddc53 --- /dev/null +++ b/tests/SpecTests/crud/updateMany-hint-clientError.json @@ -0,0 +1,110 @@ +{ + "runOn": [ + { + "maxServerVersion": "3.3.99" + } + ], + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + } + ], + "collection_name": "test_updatemany_hint", + "tests": [ + { + "description": "UpdateMany with hint string unsupported (client-side error)", + "operations": [ + { + "object": "collection", + "name": "updateMany", + "arguments": { + "filter": { + "_id": { + "$gt": 1 + } + }, + "update": { + "$inc": { + "x": 1 + } + }, + "hint": "_id_" + }, + "error": true + } + ], + "expectations": [], + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + } + ] + } + } + }, + { + "description": "UpdateMany with hint document unsupported (client-side error)", + "operations": [ + { + "object": "collection", + "name": "updateMany", + "arguments": { + "filter": { + "_id": { + "$gt": 1 + } + }, + "update": { + "$inc": { + "x": 1 + } + }, + "hint": { + "_id": 1 + } + }, + "error": true + } + ], + "expectations": [], + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + } + ] + } + } + } + ] +} diff --git a/tests/SpecTests/crud/updateMany-hint-serverError.json b/tests/SpecTests/crud/updateMany-hint-serverError.json new file mode 100644 index 000000000..86f21246e --- /dev/null +++ b/tests/SpecTests/crud/updateMany-hint-serverError.json @@ -0,0 +1,161 @@ +{ + "runOn": [ + { + "minServerVersion": "3.4.0", + "maxServerVersion": "4.1.9" + } + ], + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + } + ], + "collection_name": "test_updatemany_hint", + "tests": [ + { + "description": "UpdateMany with hint string unsupported (server-side error)", + "operations": [ + { + "object": "collection", + "name": "updateMany", + "arguments": { + "filter": { + "_id": { + "$gt": 1 + } + }, + "update": { + "$inc": { + "x": 1 + } + }, + "hint": "_id_" + }, + "error": true + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "update": "test_updatemany_hint", + "updates": [ + { + "q": { + "_id": { + "$gt": 1 + } + }, + "u": { + "$inc": { + "x": 1 + } + }, + "multi": true, + "hint": "_id_" + } + ] + } + } + } + ], + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + } + ] + } + } + }, + { + "description": "UpdateMany with hint document unsupported (server-side error)", + "operations": [ + { + "object": "collection", + "name": "updateMany", + "arguments": { + "filter": { + "_id": { + "$gt": 1 + } + }, + "update": { + "$inc": { + "x": 1 + } + }, + "hint": { + "_id": 1 + } + }, + "error": true + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "update": "test_updatemany_hint", + "updates": [ + { + "q": { + "_id": { + "$gt": 1 + } + }, + "u": { + "$inc": { + "x": 1 + } + }, + "multi": true, + "hint": { + "_id": 1 + } + } + ] + } + } + } + ], + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + } + ] + } + } + } + ] +} diff --git a/tests/SpecTests/crud/updateOne-hint-clientError.json b/tests/SpecTests/crud/updateOne-hint-clientError.json new file mode 100644 index 000000000..82bfe368c --- /dev/null +++ b/tests/SpecTests/crud/updateOne-hint-clientError.json @@ -0,0 +1,98 @@ +{ + "runOn": [ + { + "maxServerVersion": "3.3.99" + } + ], + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ], + "collection_name": "test_updateone_hint", + "tests": [ + { + "description": "UpdateOne with hint string unsupported (client-side error)", + "operations": [ + { + "object": "collection", + "name": "updateOne", + "arguments": { + "filter": { + "_id": { + "$gt": 1 + } + }, + "update": { + "$inc": { + "x": 1 + } + }, + "hint": "_id_" + }, + "error": true + } + ], + "expectations": [], + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ] + } + } + }, + { + "description": "UpdateOne with hint document unsupported (client-side error)", + "operations": [ + { + "object": "collection", + "name": "updateOne", + "arguments": { + "filter": { + "_id": { + "$gt": 1 + } + }, + "update": { + "$inc": { + "x": 1 + } + }, + "hint": { + "_id": 1 + } + }, + "error": true + } + ], + "expectations": [], + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ] + } + } + } + ] +} diff --git a/tests/SpecTests/crud/updateOne-hint-serverError.json b/tests/SpecTests/crud/updateOne-hint-serverError.json new file mode 100644 index 000000000..8e8037eb8 --- /dev/null +++ b/tests/SpecTests/crud/updateOne-hint-serverError.json @@ -0,0 +1,147 @@ +{ + "runOn": [ + { + "minServerVersion": "3.4.0", + "maxServerVersion": "4.1.9" + } + ], + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ], + "collection_name": "test_updateone_hint", + "tests": [ + { + "description": "UpdateOne with hint string unsupported (server-side error)", + "operations": [ + { + "object": "collection", + "name": "updateOne", + "arguments": { + "filter": { + "_id": { + "$gt": 1 + } + }, + "update": { + "$inc": { + "x": 1 + } + }, + "hint": "_id_" + }, + "error": true + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "update": "test_updateone_hint", + "updates": [ + { + "q": { + "_id": { + "$gt": 1 + } + }, + "u": { + "$inc": { + "x": 1 + } + }, + "hint": "_id_" + } + ] + } + } + } + ], + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ] + } + } + }, + { + "description": "UpdateOne with hint document unsupported (server-side error)", + "operations": [ + { + "object": "collection", + "name": "updateOne", + "arguments": { + "filter": { + "_id": { + "$gt": 1 + } + }, + "update": { + "$inc": { + "x": 1 + } + }, + "hint": { + "_id": 1 + } + }, + "error": true + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "update": "test_updateone_hint", + "updates": [ + { + "q": { + "_id": { + "$gt": 1 + } + }, + "u": { + "$inc": { + "x": 1 + } + }, + "hint": { + "_id": 1 + } + } + ] + } + } + } + ], + "outcome": { + "collection": { + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ] + } + } + } + ] +}