From 6e4e90a882e64274d7b3ce44971c83e5a0dbeb58 Mon Sep 17 00:00:00 2001 From: Shane Harvey Date: Mon, 2 May 2022 16:32:05 -0700 Subject: [PATCH] PYTHON-3167 Revert to using the count command for estimated_document_count (#934) Resolves PYTHON-2885, PYTHON-3166, PYTHON-3224, and PYTHON-3219. --- .evergreen/resync-specs.sh | 42 +- doc/changelog.rst | 31 + pymongo/collection.py | 29 +- .../timeseries-collection.json | 16 - test/crud/unified/aggregate-allowdiskuse.json | 155 +++ test/crud/unified/bulkWrite-comment.json | 25 + .../unified/bulkWrite-replaceOne-let.json | 12 + test/crud/unified/countDocuments-comment.json | 208 ++++ test/crud/unified/deleteMany-comment.json | 1 + test/crud/unified/deleteOne-comment.json | 1 + .../estimatedDocumentCount-comment.json | 170 ++++ test/crud/unified/estimatedDocumentCount.json | 395 ++------ test/crud/unified/find-allowdiskuse.json | 4 +- test/crud/unified/insertMany-comment.json | 1 + test/crud/unified/insertOne-comment.json | 1 + test/crud/unified/replaceOne-comment.json | 19 + test/crud/unified/replaceOne-let.json | 12 + test/crud/unified/updateMany-comment.json | 16 +- test/crud/unified/updateMany-let.json | 10 +- test/crud/unified/updateOne-comment.json | 19 + test/crud/unified/updateOne-let.json | 16 +- test/data_lake/estimatedDocumentCount.json | 19 +- .../legacy/estimatedDocumentCount-4.9.json | 246 ----- ...timatedDocumentCount-serverErrors-4.9.json | 911 ------------------ ... estimatedDocumentCount-serverErrors.json} | 2 - ...re4.9.json => estimatedDocumentCount.json} | 2 - test/unified_format.py | 17 +- .../crud-api-version-1-strict.json | 26 +- test/versioned-api/crud-api-version-1.json | 28 +- 29 files changed, 859 insertions(+), 1575 deletions(-) create mode 100644 test/crud/unified/aggregate-allowdiskuse.json create mode 100644 test/crud/unified/countDocuments-comment.json create mode 100644 test/crud/unified/estimatedDocumentCount-comment.json delete mode 100644 test/retryable_reads/legacy/estimatedDocumentCount-4.9.json delete mode 100644 test/retryable_reads/legacy/estimatedDocumentCount-serverErrors-4.9.json rename test/retryable_reads/legacy/{estimatedDocumentCount-serverErrors-pre4.9.json => estimatedDocumentCount-serverErrors.json} (99%) rename test/retryable_reads/legacy/{estimatedDocumentCount-pre4.9.json => estimatedDocumentCount.json} (97%) diff --git a/.evergreen/resync-specs.sh b/.evergreen/resync-specs.sh index af4228d08..a98b091d5 100755 --- a/.evergreen/resync-specs.sh +++ b/.evergreen/resync-specs.sh @@ -68,17 +68,24 @@ cpjson () { for spec in "$@" do + # Match the spec dir name, the python test dir name, and/or common abbreviations. case "$spec" in - bson*corpus) + atlas-data-lake-testing|data_lake) + cpjson atlas-data-lake-testing/tests/ data_lake + ;; + bson-corpus|bson_corpus) cpjson bson-corpus/tests/ bson_corpus ;; - max*staleness) + max-staleness|max_staleness) cpjson max-staleness/tests/ max_staleness ;; - connection*string) + collection-management|collection_management) + cpjson collection-management/tests/ collection_management + ;; + connection-string|connection_string) cpjson connection-string/tests/ connection_string/test ;; - change*streams) + change-streams|change_streams) cpjson change-streams/tests/ change_streams/ ;; client-side-encryption|csfle|fle) @@ -87,32 +94,29 @@ do cpjson client-side-encryption/external/ client-side-encryption/external cpjson client-side-encryption/limits/ client-side-encryption/limits ;; - cmap|CMAP) + cmap|CMAP|connection-monitoring-and-pooling) cpjson connection-monitoring-and-pooling/tests cmap rm $PYMONGO/test/cmap/wait-queue-fairness.json # PYTHON-1873 ;; - command*monitoring) + apm|APM|command-monitoring|command_monitoring) cpjson command-monitoring/tests command_monitoring ;; crud|CRUD) cpjson crud/tests/ crud ;; - load*balancer) + load-balancers|load_balancer) cpjson load-balancers/tests load_balancer ;; - initial-dns-seedlist-discovery|srv_seedlist) + srv|SRV|initial-dns-seedlist-discovery|srv_seedlist) cpjson initial-dns-seedlist-discovery/tests/ srv_seedlist ;; - old_srv_seedlist) - cpjson initial-dns-seedlist-discovery/tests srv_seedlist - ;; - retryable*reads) + retryable-reads|retryable_reads) cpjson retryable-reads/tests/ retryable_reads ;; - retryable*writes) + retryable-writes|retryable_writes) cpjson retryable-writes/tests/ retryable_writes ;; - sdam|SDAM) + sdam|SDAM|server-discovery-and-monitoring|discovery_and_monitoring) cpjson server-discovery-and-monitoring/tests/errors \ discovery_and_monitoring/errors cpjson server-discovery-and-monitoring/tests/rs \ @@ -126,10 +130,10 @@ do cpjson server-discovery-and-monitoring/tests/load-balanced \ discovery_and_monitoring/load-balanced ;; - sdam*monitoring) + sdam-monitoring|sdam_monitoring) cpjson server-discovery-and-monitoring/tests/monitoring sdam_monitoring ;; - server*selection) + server-selection|server_selection) cpjson server-selection/tests/ server_selection ;; sessions) @@ -140,13 +144,13 @@ do cpjson transactions-convenient-api/tests/ transactions-convenient-api rm $PYMONGO/test/transactions/legacy/errors-client.json # PYTHON-1894 ;; - unified) + unified|unified-test-format) cpjson unified-test-format/tests/ unified-test-format/ ;; - uri|uri*options) + uri|uri-options|uri_options) cpjson uri-options/tests uri_options ;; - stable-api) + stable-api|versioned-api) cpjson versioned-api/tests versioned-api ;; *) diff --git a/doc/changelog.rst b/doc/changelog.rst index 0fe230012..3d2f7cadc 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -1,6 +1,37 @@ Changelog ========= +Changes in Version 4.2 +---------------------- + +Bug fixes +......... + +- Fixed a bug where :meth:`~pymongo.collection.Collection.estimated_document_count` + would fail with a "CommandNotSupportedOnView" error on views (`PYTHON-2885`_). + +Unavoidable breaking changes +............................ + +- :meth:`~pymongo.collection.Collection.estimated_document_count` now always uses + the `count`_ command. Due to an oversight in versions 5.0.0-5.0.8 of MongoDB, + the count command was not included in V1 of the :ref:`versioned-api-ref`. + Users of the Stable API with estimated_document_count are recommended to upgrade + their server version to 5.0.9+ or set :attr:`pymongo.server_api.ServerApi.strict` + to ``False`` to avoid encountering errors (`PYTHON-3167`_). + +.. _count: https://mongodb.com/docs/manual/reference/command/count/ + +Issues Resolved +............... + +See the `PyMongo 4.2 release notes in JIRA`_ for the list of resolved issues +in this release. + +.. _PYTHON-2885: https://jira.mongodb.org/browse/PYTHON-2885 +.. _PYTHON-3167: https://jira.mongodb.org/browse/PYTHON-3167 +.. _PyMongo 4.2 release notes in JIRA: https://jira.mongodb.org/secure/ReleaseNote.jspa?projectId=10004&version=33196 + Changes in Version 4.1.1 ------------------------- diff --git a/pymongo/collection.py b/pymongo/collection.py index 1d0eb1035..019719810 100644 --- a/pymongo/collection.py +++ b/pymongo/collection.py @@ -1707,8 +1707,15 @@ class Collection(common.BaseObject, Generic[_DocumentType]): command. - `**kwargs` (optional): See list of options above. + .. versionchanged:: 4.2 + This method now always uses the `count`_ command. Due to an oversight in versions + 5.0.0-5.0.8 of MongoDB, the count command was not included in V1 of the + :ref:`versioned-api-ref`. Users of the Stable API with estimated_document_count are + recommended to upgrade their server version to 5.0.9+ or set + :attr:`pymongo.server_api.ServerApi.strict` to ``False`` to avoid encountering errors. .. versionadded:: 3.7 + .. _count: https://mongodb.com/docs/manual/reference/command/count/ """ if "session" in kwargs: raise ConfigurationError("estimated_document_count does not support sessions") @@ -1716,25 +1723,9 @@ class Collection(common.BaseObject, Generic[_DocumentType]): kwargs["comment"] = comment def _cmd(session, server, sock_info, read_preference): - if sock_info.max_wire_version >= 12: - # MongoDB 4.9+ - pipeline = [ - {"$collStats": {"count": {}}}, - {"$group": {"_id": 1, "n": {"$sum": "$count"}}}, - ] - cmd = SON([("aggregate", self.__name), ("pipeline", pipeline), ("cursor", {})]) - cmd.update(kwargs) - result = self._aggregate_one_result( - sock_info, read_preference, cmd, collation=None, session=session - ) - if not result: - return 0 - return int(result["n"]) - else: - # MongoDB < 4.9 - cmd = SON([("count", self.__name)]) - cmd.update(kwargs) - return self._count_cmd(session, sock_info, read_preference, cmd, collation=None) + cmd = SON([("count", self.__name)]) + cmd.update(kwargs) + return self._count_cmd(session, sock_info, read_preference, cmd, collation=None) return self._retryable_non_cursor_read(_cmd, None) diff --git a/test/collection_management/timeseries-collection.json b/test/collection_management/timeseries-collection.json index 99f642e59..b5638fd36 100644 --- a/test/collection_management/timeseries-collection.json +++ b/test/collection_management/timeseries-collection.json @@ -82,14 +82,6 @@ "databaseName": "ts-tests" } }, - { - "commandStartedEvent": { - "command": { - "listCollections": 1 - }, - "databaseName": "ts-tests" - } - }, { "commandStartedEvent": { "command": { @@ -204,14 +196,6 @@ "databaseName": "ts-tests" } }, - { - "commandStartedEvent": { - "command": { - "listCollections": 1 - }, - "databaseName": "ts-tests" - } - }, { "commandStartedEvent": { "command": { diff --git a/test/crud/unified/aggregate-allowdiskuse.json b/test/crud/unified/aggregate-allowdiskuse.json new file mode 100644 index 000000000..2e54175b8 --- /dev/null +++ b/test/crud/unified/aggregate-allowdiskuse.json @@ -0,0 +1,155 @@ +{ + "description": "aggregate-allowdiskuse", + "schemaVersion": "1.0", + "createEntities": [ + { + "client": { + "id": "client0", + "observeEvents": [ + "commandStartedEvent" + ] + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "crud-tests" + } + }, + { + "collection": { + "id": "collection0", + "database": "database0", + "collectionName": "coll0" + } + } + ], + "initialData": [ + { + "collectionName": "coll0", + "databaseName": "crud-tests", + "documents": [] + } + ], + "tests": [ + { + "description": "Aggregate does not send allowDiskUse when value is not specified", + "operations": [ + { + "object": "collection0", + "name": "aggregate", + "arguments": { + "pipeline": [ + { + "$match": {} + } + ] + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "aggregate": "coll0", + "pipeline": [ + { + "$match": {} + } + ], + "allowDiskUse": { + "$$exists": false + } + }, + "commandName": "aggregate", + "databaseName": "crud-tests" + } + } + ] + } + ] + }, + { + "description": "Aggregate sends allowDiskUse false when false is specified", + "operations": [ + { + "object": "collection0", + "name": "aggregate", + "arguments": { + "pipeline": [ + { + "$match": {} + } + ], + "allowDiskUse": false + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "aggregate": "coll0", + "pipeline": [ + { + "$match": {} + } + ], + "allowDiskUse": false + }, + "commandName": "aggregate", + "databaseName": "crud-tests" + } + } + ] + } + ] + }, + { + "description": "Aggregate sends allowDiskUse true when true is specified", + "operations": [ + { + "object": "collection0", + "name": "aggregate", + "arguments": { + "pipeline": [ + { + "$match": {} + } + ], + "allowDiskUse": true + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "aggregate": "coll0", + "pipeline": [ + { + "$match": {} + } + ], + "allowDiskUse": true + }, + "commandName": "aggregate", + "databaseName": "crud-tests" + } + } + ] + } + ] + } + ] +} diff --git a/test/crud/unified/bulkWrite-comment.json b/test/crud/unified/bulkWrite-comment.json index fac964454..0b2addc85 100644 --- a/test/crud/unified/bulkWrite-comment.json +++ b/test/crud/unified/bulkWrite-comment.json @@ -150,6 +150,12 @@ "u": { "_id": 1, "x": "replaced" + }, + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false } }, { @@ -160,6 +166,12 @@ "$set": { "x": "updated" } + }, + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false } } ], @@ -317,6 +329,12 @@ "u": { "_id": 1, "x": "replaced" + }, + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false } }, { @@ -327,6 +345,12 @@ "$set": { "x": "updated" } + }, + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false } } ], @@ -388,6 +412,7 @@ "description": "BulkWrite with comment - pre 4.4", "runOnRequirements": [ { + "minServerVersion": "3.4.0", "maxServerVersion": "4.2.99" } ], diff --git a/test/crud/unified/bulkWrite-replaceOne-let.json b/test/crud/unified/bulkWrite-replaceOne-let.json index df4eafe62..70f63837a 100644 --- a/test/crud/unified/bulkWrite-replaceOne-let.json +++ b/test/crud/unified/bulkWrite-replaceOne-let.json @@ -95,6 +95,12 @@ }, "u": { "x": 3 + }, + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false } } ], @@ -183,6 +189,12 @@ }, "u": { "x": 3 + }, + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false } } ], diff --git a/test/crud/unified/countDocuments-comment.json b/test/crud/unified/countDocuments-comment.json new file mode 100644 index 000000000..e6c7ae817 --- /dev/null +++ b/test/crud/unified/countDocuments-comment.json @@ -0,0 +1,208 @@ +{ + "description": "countDocuments-comment", + "schemaVersion": "1.0", + "createEntities": [ + { + "client": { + "id": "client0", + "observeEvents": [ + "commandStartedEvent" + ] + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "countDocuments-comments-test" + } + }, + { + "collection": { + "id": "collection0", + "database": "database0", + "collectionName": "coll0" + } + } + ], + "initialData": [ + { + "collectionName": "coll0", + "databaseName": "countDocuments-comments-test", + "documents": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + } + ] + } + ], + "tests": [ + { + "description": "countDocuments with document comment", + "runOnRequirements": [ + { + "minServerVersion": "4.4.0" + } + ], + "operations": [ + { + "name": "countDocuments", + "object": "collection0", + "arguments": { + "filter": {}, + "comment": { + "key": "value" + } + }, + "expectResult": 3 + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "aggregate": "coll0", + "pipeline": [ + { + "$match": {} + }, + { + "$group": { + "_id": 1, + "n": { + "$sum": 1 + } + } + } + ], + "comment": { + "key": "value" + } + }, + "commandName": "aggregate", + "databaseName": "countDocuments-comments-test" + } + } + ] + } + ] + }, + { + "description": "countDocuments with string comment", + "runOnRequirements": [ + { + "minServerVersion": "3.6.0" + } + ], + "operations": [ + { + "name": "countDocuments", + "object": "collection0", + "arguments": { + "filter": {}, + "comment": "comment" + }, + "expectResult": 3 + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "aggregate": "coll0", + "pipeline": [ + { + "$match": {} + }, + { + "$group": { + "_id": 1, + "n": { + "$sum": 1 + } + } + } + ], + "comment": "comment" + }, + "commandName": "aggregate", + "databaseName": "countDocuments-comments-test" + } + } + ] + } + ] + }, + { + "description": "countDocuments with document comment on less than 4.4.0 - server error", + "runOnRequirements": [ + { + "minServerVersion": "3.6.0", + "maxServerVersion": "4.3.99" + } + ], + "operations": [ + { + "name": "countDocuments", + "object": "collection0", + "arguments": { + "filter": {}, + "comment": { + "key": "value" + } + }, + "expectError": { + "isClientError": false + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "aggregate": "coll0", + "pipeline": [ + { + "$match": {} + }, + { + "$group": { + "_id": 1, + "n": { + "$sum": 1 + } + } + } + ], + "comment": { + "key": "value" + } + }, + "commandName": "aggregate", + "databaseName": "countDocuments-comments-test" + } + } + ] + } + ] + } + ] +} diff --git a/test/crud/unified/deleteMany-comment.json b/test/crud/unified/deleteMany-comment.json index ea6a8524d..6abc5fd58 100644 --- a/test/crud/unified/deleteMany-comment.json +++ b/test/crud/unified/deleteMany-comment.json @@ -175,6 +175,7 @@ "description": "deleteMany with comment - pre 4.4", "runOnRequirements": [ { + "minServerVersion": "3.4.0", "maxServerVersion": "4.2.99" } ], diff --git a/test/crud/unified/deleteOne-comment.json b/test/crud/unified/deleteOne-comment.json index 37f356ec6..0f42b086a 100644 --- a/test/crud/unified/deleteOne-comment.json +++ b/test/crud/unified/deleteOne-comment.json @@ -177,6 +177,7 @@ "description": "deleteOne with comment - pre 4.4", "runOnRequirements": [ { + "minServerVersion": "3.4.0", "maxServerVersion": "4.2.99" } ], diff --git a/test/crud/unified/estimatedDocumentCount-comment.json b/test/crud/unified/estimatedDocumentCount-comment.json new file mode 100644 index 000000000..6c0adacc8 --- /dev/null +++ b/test/crud/unified/estimatedDocumentCount-comment.json @@ -0,0 +1,170 @@ +{ + "description": "estimatedDocumentCount-comment", + "schemaVersion": "1.0", + "createEntities": [ + { + "client": { + "id": "client0", + "observeEvents": [ + "commandStartedEvent" + ] + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "edc-comment-tests" + } + }, + { + "collection": { + "id": "collection0", + "database": "database0", + "collectionName": "coll0" + } + } + ], + "initialData": [ + { + "collectionName": "coll0", + "databaseName": "edc-comment-tests", + "documents": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + } + ] + } + ], + "tests": [ + { + "description": "estimatedDocumentCount with document comment", + "runOnRequirements": [ + { + "minServerVersion": "4.4.14" + } + ], + "operations": [ + { + "name": "estimatedDocumentCount", + "object": "collection0", + "arguments": { + "comment": { + "key": "value" + } + }, + "expectResult": 3 + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "count": "coll0", + "comment": { + "key": "value" + } + }, + "commandName": "count", + "databaseName": "edc-comment-tests" + } + } + ] + } + ] + }, + { + "description": "estimatedDocumentCount with string comment", + "runOnRequirements": [ + { + "minServerVersion": "4.4.0" + } + ], + "operations": [ + { + "name": "estimatedDocumentCount", + "object": "collection0", + "arguments": { + "comment": "comment" + }, + "expectResult": 3 + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "count": "coll0", + "comment": "comment" + }, + "commandName": "count", + "databaseName": "edc-comment-tests" + } + } + ] + } + ] + }, + { + "description": "estimatedDocumentCount with document comment - pre 4.4.14, server error", + "runOnRequirements": [ + { + "minServerVersion": "3.6.0", + "maxServerVersion": "4.4.13", + "topologies": [ + "single", + "replicaset" + ] + } + ], + "operations": [ + { + "name": "estimatedDocumentCount", + "object": "collection0", + "arguments": { + "comment": { + "key": "value" + } + }, + "expectError": { + "isClientError": false + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "count": "coll0", + "comment": { + "key": "value" + } + }, + "commandName": "count", + "databaseName": "edc-comment-tests" + } + } + ] + } + ] + } + ] +} diff --git a/test/crud/unified/estimatedDocumentCount.json b/test/crud/unified/estimatedDocumentCount.json index bcd66ea95..1b650c1cb 100644 --- a/test/crud/unified/estimatedDocumentCount.json +++ b/test/crud/unified/estimatedDocumentCount.json @@ -34,6 +34,13 @@ "database": "database0", "collectionName": "coll1" } + }, + { + "collection": { + "id": "collection0View", + "database": "database0", + "collectionName": "coll0view" + } } ], "initialData": [ @@ -58,288 +65,7 @@ ], "tests": [ { - "description": "estimatedDocumentCount uses $collStats on 4.9.0 or greater", - "runOnRequirements": [ - { - "minServerVersion": "4.9.0" - } - ], - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection0", - "expectResult": 3 - } - ], - "expectEvents": [ - { - "client": "client0", - "events": [ - { - "commandStartedEvent": { - "command": { - "aggregate": "coll0", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "commandName": "aggregate", - "databaseName": "edc-tests" - } - } - ] - } - ] - }, - { - "description": "estimatedDocumentCount with maxTimeMS on 4.9.0 or greater", - "runOnRequirements": [ - { - "minServerVersion": "4.9.0" - } - ], - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection0", - "arguments": { - "maxTimeMS": 6000 - }, - "expectResult": 3 - } - ], - "expectEvents": [ - { - "client": "client0", - "events": [ - { - "commandStartedEvent": { - "command": { - "aggregate": "coll0", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ], - "maxTimeMS": 6000 - }, - "commandName": "aggregate", - "databaseName": "edc-tests" - } - } - ] - } - ] - }, - { - "description": "estimatedDocumentCount on non-existent collection on 4.9.0 or greater", - "runOnRequirements": [ - { - "minServerVersion": "4.9.0" - } - ], - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection1", - "expectResult": 0 - } - ], - "expectEvents": [ - { - "client": "client0", - "events": [ - { - "commandStartedEvent": { - "command": { - "aggregate": "coll1", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "commandName": "aggregate", - "databaseName": "edc-tests" - } - } - ] - } - ] - }, - { - "description": "estimatedDocumentCount errors correctly on 4.9.0 or greater--command error", - "runOnRequirements": [ - { - "minServerVersion": "4.9.0" - } - ], - "operations": [ - { - "name": "failPoint", - "object": "testRunner", - "arguments": { - "client": "client0", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "aggregate" - ], - "errorCode": 8 - } - } - } - }, - { - "name": "estimatedDocumentCount", - "object": "collection0", - "expectError": { - "errorCode": 8 - } - } - ], - "expectEvents": [ - { - "client": "client0", - "events": [ - { - "commandStartedEvent": { - "command": { - "aggregate": "coll0", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "commandName": "aggregate", - "databaseName": "edc-tests" - } - } - ] - } - ] - }, - { - "description": "estimatedDocumentCount errors correctly on 4.9.0 or greater--socket error", - "runOnRequirements": [ - { - "minServerVersion": "4.9.0" - } - ], - "operations": [ - { - "name": "failPoint", - "object": "testRunner", - "arguments": { - "client": "client0", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "aggregate" - ], - "closeConnection": true - } - } - } - }, - { - "name": "estimatedDocumentCount", - "object": "collection0", - "expectError": { - "isError": true - } - } - ], - "expectEvents": [ - { - "client": "client0", - "events": [ - { - "commandStartedEvent": { - "command": { - "aggregate": "coll0", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "commandName": "aggregate", - "databaseName": "edc-tests" - } - } - ] - } - ] - }, - { - "description": "estimatedDocumentCount uses count on less than 4.9.0", - "runOnRequirements": [ - { - "maxServerVersion": "4.8.99" - } - ], + "description": "estimatedDocumentCount always uses count", "operations": [ { "name": "estimatedDocumentCount", @@ -365,12 +91,7 @@ ] }, { - "description": "estimatedDocumentCount with maxTimeMS on less than 4.9.0", - "runOnRequirements": [ - { - "maxServerVersion": "4.8.99" - } - ], + "description": "estimatedDocumentCount with maxTimeMS", "operations": [ { "name": "estimatedDocumentCount", @@ -400,12 +121,7 @@ ] }, { - "description": "estimatedDocumentCount on non-existent collection on less than 4.9.0", - "runOnRequirements": [ - { - "maxServerVersion": "4.8.99" - } - ], + "description": "estimatedDocumentCount on non-existent collection", "operations": [ { "name": "estimatedDocumentCount", @@ -431,11 +147,10 @@ ] }, { - "description": "estimatedDocumentCount errors correctly on less than 4.9.0--command error", + "description": "estimatedDocumentCount errors correctly--command error", "runOnRequirements": [ { "minServerVersion": "4.0.0", - "maxServerVersion": "4.8.99", "topologies": [ "single", "replicaset" @@ -443,7 +158,6 @@ }, { "minServerVersion": "4.2.0", - "maxServerVersion": "4.8.99", "topologies": [ "sharded" ] @@ -495,11 +209,10 @@ ] }, { - "description": "estimatedDocumentCount errors correctly on less than 4.9.0--socket error", + "description": "estimatedDocumentCount errors correctly--socket error", "runOnRequirements": [ { "minServerVersion": "4.0.0", - "maxServerVersion": "4.8.99", "topologies": [ "single", "replicaset" @@ -507,7 +220,6 @@ }, { "minServerVersion": "4.2.0", - "maxServerVersion": "4.8.99", "topologies": [ "sharded" ] @@ -557,6 +269,89 @@ ] } ] + }, + { + "description": "estimatedDocumentCount works correctly on views", + "runOnRequirements": [ + { + "minServerVersion": "3.4.0" + } + ], + "operations": [ + { + "name": "dropCollection", + "object": "database0", + "arguments": { + "collection": "coll0view" + } + }, + { + "name": "createCollection", + "object": "database0", + "arguments": { + "collection": "coll0view", + "viewOn": "coll0", + "pipeline": [ + { + "$match": { + "_id": { + "$gt": 1 + } + } + } + ] + } + }, + { + "name": "estimatedDocumentCount", + "object": "collection0View", + "expectResult": 2 + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "drop": "coll0view" + }, + "commandName": "drop", + "databaseName": "edc-tests" + } + }, + { + "commandStartedEvent": { + "command": { + "create": "coll0view", + "viewOn": "coll0", + "pipeline": [ + { + "$match": { + "_id": { + "$gt": 1 + } + } + } + ] + }, + "commandName": "create", + "databaseName": "edc-tests" + } + }, + { + "commandStartedEvent": { + "command": { + "count": "coll0view" + }, + "commandName": "count", + "databaseName": "edc-tests" + } + } + ] + } + ] } ] } diff --git a/test/crud/unified/find-allowdiskuse.json b/test/crud/unified/find-allowdiskuse.json index 789bb7fbf..eb238ab93 100644 --- a/test/crud/unified/find-allowdiskuse.json +++ b/test/crud/unified/find-allowdiskuse.json @@ -32,7 +32,7 @@ ], "tests": [ { - "description": "Find does not send allowDiskuse when value is not specified", + "description": "Find does not send allowDiskUse when value is not specified", "operations": [ { "object": "collection0", @@ -61,7 +61,7 @@ ] }, { - "description": "Find sends allowDiskuse false when false is specified", + "description": "Find sends allowDiskUse false when false is specified", "operations": [ { "object": "collection0", diff --git a/test/crud/unified/insertMany-comment.json b/test/crud/unified/insertMany-comment.json index 7e835e801..2b4c80b3f 100644 --- a/test/crud/unified/insertMany-comment.json +++ b/test/crud/unified/insertMany-comment.json @@ -166,6 +166,7 @@ "description": "insertMany with comment - pre 4.4", "runOnRequirements": [ { + "minServerVersion": "3.4.0", "maxServerVersion": "4.2.99" } ], diff --git a/test/crud/unified/insertOne-comment.json b/test/crud/unified/insertOne-comment.json index a9f735ab6..dbd83d9f6 100644 --- a/test/crud/unified/insertOne-comment.json +++ b/test/crud/unified/insertOne-comment.json @@ -162,6 +162,7 @@ "description": "insertOne with comment - pre 4.4", "runOnRequirements": [ { + "minServerVersion": "3.4.0", "maxServerVersion": "4.2.99" } ], diff --git a/test/crud/unified/replaceOne-comment.json b/test/crud/unified/replaceOne-comment.json index 02fe90a44..88bee5d7b 100644 --- a/test/crud/unified/replaceOne-comment.json +++ b/test/crud/unified/replaceOne-comment.json @@ -75,6 +75,12 @@ }, "u": { "x": 22 + }, + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false } } ], @@ -137,6 +143,12 @@ }, "u": { "x": 22 + }, + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false } } ], @@ -166,6 +178,7 @@ "description": "ReplaceOne with comment - pre 4.4", "runOnRequirements": [ { + "minServerVersion": "3.4.0", "maxServerVersion": "4.2.99" } ], @@ -202,6 +215,12 @@ }, "u": { "x": 22 + }, + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false } } ], diff --git a/test/crud/unified/replaceOne-let.json b/test/crud/unified/replaceOne-let.json index 6cf8e1567..e7a7ee65a 100644 --- a/test/crud/unified/replaceOne-let.json +++ b/test/crud/unified/replaceOne-let.json @@ -94,6 +94,12 @@ }, "u": { "x": "foo" + }, + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false } } ], @@ -176,6 +182,12 @@ }, "u": { "x": "foo" + }, + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false } } ], diff --git a/test/crud/unified/updateMany-comment.json b/test/crud/unified/updateMany-comment.json index 26abd92ed..88b8b67f5 100644 --- a/test/crud/unified/updateMany-comment.json +++ b/test/crud/unified/updateMany-comment.json @@ -80,7 +80,10 @@ "x": 22 } }, - "multi": true + "multi": true, + "upsert": { + "$$unsetOrMatches": false + } } ], "comment": "comment" @@ -147,7 +150,10 @@ "x": 22 } }, - "multi": true + "multi": true, + "upsert": { + "$$unsetOrMatches": false + } } ], "comment": { @@ -176,6 +182,7 @@ "description": "UpdateMany with comment - pre 4.4", "runOnRequirements": [ { + "minServerVersion": "3.4.0", "maxServerVersion": "4.2.99" } ], @@ -217,7 +224,10 @@ "x": 22 } }, - "multi": true + "multi": true, + "upsert": { + "$$unsetOrMatches": false + } } ], "comment": "comment" diff --git a/test/crud/unified/updateMany-let.json b/test/crud/unified/updateMany-let.json index 8a19ac093..cff3bd4c7 100644 --- a/test/crud/unified/updateMany-let.json +++ b/test/crud/unified/updateMany-let.json @@ -114,7 +114,10 @@ } } ], - "multi": true + "multi": true, + "upsert": { + "$$unsetOrMatches": false + } } ], "let": { @@ -207,7 +210,10 @@ } } ], - "multi": true + "multi": true, + "upsert": { + "$$unsetOrMatches": false + } } ], "let": { diff --git a/test/crud/unified/updateOne-comment.json b/test/crud/unified/updateOne-comment.json index 9b3b71d39..f4ee74db3 100644 --- a/test/crud/unified/updateOne-comment.json +++ b/test/crud/unified/updateOne-comment.json @@ -79,6 +79,12 @@ "$set": { "x": 22 } + }, + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false } } ], @@ -145,6 +151,12 @@ "$set": { "x": 22 } + }, + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false } } ], @@ -174,6 +186,7 @@ "description": "UpdateOne with comment - pre 4.4", "runOnRequirements": [ { + "minServerVersion": "3.4.0", "maxServerVersion": "4.2.99" } ], @@ -214,6 +227,12 @@ "$set": { "x": 22 } + }, + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false } } ], diff --git a/test/crud/unified/updateOne-let.json b/test/crud/unified/updateOne-let.json index 8237bef7e..e43b97935 100644 --- a/test/crud/unified/updateOne-let.json +++ b/test/crud/unified/updateOne-let.json @@ -103,7 +103,13 @@ "x": "$$x" } } - ] + ], + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false + } } ], "let": { @@ -184,7 +190,13 @@ "x": "$$x" } } - ] + ], + "multi": { + "$$unsetOrMatches": false + }, + "upsert": { + "$$unsetOrMatches": false + } } ], "let": { diff --git a/test/data_lake/estimatedDocumentCount.json b/test/data_lake/estimatedDocumentCount.json index 87b385208..997a3ab3f 100644 --- a/test/data_lake/estimatedDocumentCount.json +++ b/test/data_lake/estimatedDocumentCount.json @@ -15,24 +15,9 @@ { "command_started_event": { "command": { - "aggregate": "driverdata", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] + "count": "driverdata" }, - "command_name": "aggregate", + "command_name": "count", "database_name": "test" } } diff --git a/test/retryable_reads/legacy/estimatedDocumentCount-4.9.json b/test/retryable_reads/legacy/estimatedDocumentCount-4.9.json deleted file mode 100644 index a4c46fc07..000000000 --- a/test/retryable_reads/legacy/estimatedDocumentCount-4.9.json +++ /dev/null @@ -1,246 +0,0 @@ -{ - "runOn": [ - { - "minServerVersion": "4.9.0" - } - ], - "database_name": "retryable-reads-tests", - "collection_name": "coll", - "data": [ - { - "_id": 1, - "x": 11 - }, - { - "_id": 2, - "x": 22 - } - ], - "tests": [ - { - "description": "EstimatedDocumentCount succeeds on first attempt", - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "result": 2 - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount succeeds on second attempt", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "aggregate" - ], - "closeConnection": true - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "result": 2 - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - }, - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount fails on first attempt", - "clientOptions": { - "retryReads": false - }, - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "aggregate" - ], - "closeConnection": true - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "error": true - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount fails on second attempt", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 2 - }, - "data": { - "failCommands": [ - "aggregate" - ], - "closeConnection": true - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "error": true - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - }, - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - } - ] - } - ] -} diff --git a/test/retryable_reads/legacy/estimatedDocumentCount-serverErrors-4.9.json b/test/retryable_reads/legacy/estimatedDocumentCount-serverErrors-4.9.json deleted file mode 100644 index 756b02b3a..000000000 --- a/test/retryable_reads/legacy/estimatedDocumentCount-serverErrors-4.9.json +++ /dev/null @@ -1,911 +0,0 @@ -{ - "runOn": [ - { - "minServerVersion": "4.9.0" - } - ], - "database_name": "retryable-reads-tests", - "collection_name": "coll", - "data": [ - { - "_id": 1, - "x": 11 - }, - { - "_id": 2, - "x": 22 - } - ], - "tests": [ - { - "description": "EstimatedDocumentCount succeeds after InterruptedAtShutdown", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "aggregate" - ], - "errorCode": 11600 - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "result": 2 - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - }, - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount succeeds after InterruptedDueToReplStateChange", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "aggregate" - ], - "errorCode": 11602 - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "result": 2 - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - }, - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount succeeds after NotWritablePrimary", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "aggregate" - ], - "errorCode": 10107 - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "result": 2 - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - }, - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount succeeds after NotPrimaryNoSecondaryOk", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "aggregate" - ], - "errorCode": 13435 - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "result": 2 - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - }, - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount succeeds after NotPrimaryOrSecondary", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "aggregate" - ], - "errorCode": 13436 - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "result": 2 - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - }, - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount succeeds after PrimarySteppedDown", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "aggregate" - ], - "errorCode": 189 - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "result": 2 - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - }, - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount succeeds after ShutdownInProgress", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "aggregate" - ], - "errorCode": 91 - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "result": 2 - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - }, - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount succeeds after HostNotFound", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "aggregate" - ], - "errorCode": 7 - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "result": 2 - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - }, - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount succeeds after HostUnreachable", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "aggregate" - ], - "errorCode": 6 - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "result": 2 - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - }, - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount succeeds after NetworkTimeout", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "aggregate" - ], - "errorCode": 89 - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "result": 2 - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - }, - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount succeeds after SocketException", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "aggregate" - ], - "errorCode": 9001 - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "result": 2 - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - }, - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount fails after two NotWritablePrimary errors", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 2 - }, - "data": { - "failCommands": [ - "aggregate" - ], - "errorCode": 10107 - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "error": true - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - }, - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount fails after NotWritablePrimary when retryReads is false", - "clientOptions": { - "retryReads": false - }, - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "aggregate" - ], - "errorCode": 10107 - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "error": true - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - } - ] - } - ] -} diff --git a/test/retryable_reads/legacy/estimatedDocumentCount-serverErrors-pre4.9.json b/test/retryable_reads/legacy/estimatedDocumentCount-serverErrors.json similarity index 99% rename from test/retryable_reads/legacy/estimatedDocumentCount-serverErrors-pre4.9.json rename to test/retryable_reads/legacy/estimatedDocumentCount-serverErrors.json index 0b9a2615d..6bb128f5f 100644 --- a/test/retryable_reads/legacy/estimatedDocumentCount-serverErrors-pre4.9.json +++ b/test/retryable_reads/legacy/estimatedDocumentCount-serverErrors.json @@ -2,7 +2,6 @@ "runOn": [ { "minServerVersion": "4.0", - "maxServerVersion": "4.8.99", "topology": [ "single", "replicaset" @@ -10,7 +9,6 @@ }, { "minServerVersion": "4.1.7", - "maxServerVersion": "4.8.99", "topology": [ "sharded" ] diff --git a/test/retryable_reads/legacy/estimatedDocumentCount-pre4.9.json b/test/retryable_reads/legacy/estimatedDocumentCount.json similarity index 97% rename from test/retryable_reads/legacy/estimatedDocumentCount-pre4.9.json rename to test/retryable_reads/legacy/estimatedDocumentCount.json index 44be966ae..8dfa15a2c 100644 --- a/test/retryable_reads/legacy/estimatedDocumentCount-pre4.9.json +++ b/test/retryable_reads/legacy/estimatedDocumentCount.json @@ -2,7 +2,6 @@ "runOn": [ { "minServerVersion": "4.0", - "maxServerVersion": "4.8.99", "topology": [ "single", "replicaset" @@ -10,7 +9,6 @@ }, { "minServerVersion": "4.1.7", - "maxServerVersion": "4.8.99", "topology": [ "sharded" ] diff --git a/test/unified_format.py b/test/unified_format.py index 378fcc475..459566d71 100644 --- a/test/unified_format.py +++ b/test/unified_format.py @@ -226,6 +226,7 @@ class EventListenerUtil(CMAPListener, CommandListener): self._observe_sensitive_commands = False self._ignore_commands = _SENSITIVE_COMMANDS | set(ignore_commands) self._ignore_commands.add("configurefailpoint") + self.ignore_list_collections = False self._event_mapping = collections.defaultdict(list) self.entity_map = entity_map if store_events: @@ -256,7 +257,10 @@ class EventListenerUtil(CMAPListener, CommandListener): ) def _command_event(self, event): - if event.command_name.lower() not in self._ignore_commands: + if not ( + event.command_name.lower() in self._ignore_commands + or (self.ignore_list_collections and event.command_name == "listCollections") + ): self.add_event(event) def started(self, event): @@ -883,6 +887,17 @@ class UnifiedSpecTestMixinV1(IntegrationTest): cursor = target.list_collections(*args, **kwargs) return list(cursor) + def _databaseOperation_createCollection(self, target, *args, **kwargs): + # PYTHON-1936 Ignore the listCollections event from create_collection. + for listener in target.client.options.event_listeners: + if isinstance(listener, EventListenerUtil): + listener.ignore_list_collections = True + ret = target.create_collection(*args, **kwargs) + for listener in target.client.options.event_listeners: + if isinstance(listener, EventListenerUtil): + listener.ignore_list_collections = False + return ret + def __entityOperation_aggregate(self, target, *args, **kwargs): self.__raise_if_unsupported("aggregate", target, Database, Collection) return list(target.aggregate(*args, **kwargs)) diff --git a/test/versioned-api/crud-api-version-1-strict.json b/test/versioned-api/crud-api-version-1-strict.json index 29a0ec4e3..c1c8ecce0 100644 --- a/test/versioned-api/crud-api-version-1-strict.json +++ b/test/versioned-api/crud-api-version-1-strict.json @@ -613,6 +613,15 @@ }, { "description": "estimatedDocumentCount appends declared API version", + "runOnRequirements": [ + { + "minServerVersion": "5.0.9", + "maxServerVersion": "5.0.99" + }, + { + "minServerVersion": "5.3.2" + } + ], "operations": [ { "name": "estimatedDocumentCount", @@ -627,22 +636,7 @@ { "commandStartedEvent": { "command": { - "aggregate": "test", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ], + "count": "test", "apiVersion": "1", "apiStrict": true, "apiDeprecationErrors": { diff --git a/test/versioned-api/crud-api-version-1.json b/test/versioned-api/crud-api-version-1.json index 1f135eea1..a387d0587 100644 --- a/test/versioned-api/crud-api-version-1.json +++ b/test/versioned-api/crud-api-version-1.json @@ -604,7 +604,16 @@ ] }, { - "description": "estimatedDocumentCount appends declared API version on 4.9.0 or greater", + "description": "estimatedDocumentCount appends declared API version", + "runOnRequirements": [ + { + "minServerVersion": "5.0.9", + "maxServerVersion": "5.0.99" + }, + { + "minServerVersion": "5.3.2" + } + ], "operations": [ { "name": "estimatedDocumentCount", @@ -619,22 +628,7 @@ { "commandStartedEvent": { "command": { - "aggregate": "test", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ], + "count": "test", "apiVersion": "1", "apiStrict": { "$$unsetOrMatches": false