From a752e75a26025e56ab9e47e4da59e1e6ccee511f Mon Sep 17 00:00:00 2001 From: Durran Jordan Date: Wed, 18 May 2022 20:20:14 +0200 Subject: [PATCH] feat(NODE-4079): estimated document count uses count (#3244) --- src/collection.ts | 8 + src/operations/estimated_document_count.ts | 31 +- .../collection-management/collection.test.js | 112 +-- .../read-write-concern/readconcern.test.js | 2 +- .../estimatedDocumentCount.json | 19 +- .../estimatedDocumentCount.yml | 9 +- .../crud/unified/estimatedDocumentCount.json | 371 ++----- .../crud/unified/estimatedDocumentCount.yml | 184 +--- .../legacy/estimatedDocumentCount-4.9.json | 246 ----- .../legacy/estimatedDocumentCount-4.9.yml | 60 -- ...timatedDocumentCount-serverErrors-4.9.json | 911 ------------------ ...stimatedDocumentCount-serverErrors-4.9.yml | 146 --- ... estimatedDocumentCount-serverErrors.json} | 2 - ...> estimatedDocumentCount-serverErrors.yml} | 2 - ...re4.9.json => estimatedDocumentCount.json} | 2 - ...-pre4.9.yml => estimatedDocumentCount.yml} | 2 - .../crud-api-version-1-strict.json | 26 +- .../crud-api-version-1-strict.yml | 10 +- .../versioned-api/crud-api-version-1.json | 28 +- .../spec/versioned-api/crud-api-version-1.yml | 12 +- 20 files changed, 238 insertions(+), 1945 deletions(-) delete mode 100644 test/spec/retryable-reads/legacy/estimatedDocumentCount-4.9.json delete mode 100644 test/spec/retryable-reads/legacy/estimatedDocumentCount-4.9.yml delete mode 100644 test/spec/retryable-reads/legacy/estimatedDocumentCount-serverErrors-4.9.json delete mode 100644 test/spec/retryable-reads/legacy/estimatedDocumentCount-serverErrors-4.9.yml rename test/spec/retryable-reads/legacy/{estimatedDocumentCount-serverErrors-pre4.9.json => estimatedDocumentCount-serverErrors.json} (99%) rename test/spec/retryable-reads/legacy/{estimatedDocumentCount-serverErrors-pre4.9.yml => estimatedDocumentCount-serverErrors.yml} (98%) rename test/spec/retryable-reads/legacy/{estimatedDocumentCount-pre4.9.json => estimatedDocumentCount.json} (97%) rename test/spec/retryable-reads/legacy/{estimatedDocumentCount-pre4.9.yml => estimatedDocumentCount.yml} (96%) diff --git a/src/collection.ts b/src/collection.ts index 8bb2fb0b8a..f89a9f2fc5 100644 --- a/src/collection.ts +++ b/src/collection.ts @@ -1043,7 +1043,15 @@ export class Collection { /** * Gets an estimate of the count of documents in a collection using collection metadata. + * This will always run a count command on all server versions. * + * due to an oversight in versions 5.0.0-5.0.8 of MongoDB, the count command, + * which estimatedDocumentCount uses in its implementation, was not included in v1 of + * the Stable API, and so users of the Stable API with estimatedDocumentCount are + * recommended to upgrade their server version to 5.0.9+ or set apiStrict: false to avoid + * encountering errors. + * + * @see {@link https://www.mongodb.com/docs/manual/reference/command/count/#behavior|Count: Behavior} * @param options - Optional settings for the command * @param callback - An optional callback, a Promise will be returned if none is provided */ diff --git a/src/operations/estimated_document_count.ts b/src/operations/estimated_document_count.ts index 6513e5795b..d96ca44759 100644 --- a/src/operations/estimated_document_count.ts +++ b/src/operations/estimated_document_count.ts @@ -1,9 +1,8 @@ import type { Document } from '../bson'; import type { Collection } from '../collection'; -import type { MongoServerError } from '../error'; import type { Server } from '../sdam/server'; import type { ClientSession } from '../sessions'; -import { Callback, maxWireVersion } from '../utils'; +import type { Callback } from '../utils'; import { CommandOperation, CommandOperationOptions } from './command'; import { Aspect, defineAspects } from './operation'; @@ -32,32 +31,6 @@ export class EstimatedDocumentCountOperation extends CommandOperation { server: Server, session: ClientSession | undefined, callback: Callback - ): void { - if (maxWireVersion(server) < 12) { - return this.executeLegacy(server, session, callback); - } - const pipeline = [{ $collStats: { count: {} } }, { $group: { _id: 1, n: { $sum: '$count' } } }]; - - const cmd: Document = { aggregate: this.collectionName, pipeline, cursor: {} }; - - if (typeof this.options.maxTimeMS === 'number') { - cmd.maxTimeMS = this.options.maxTimeMS; - } - - super.executeCommand(server, session, cmd, (err, response) => { - if (err && (err as MongoServerError).code !== 26) { - callback(err); - return; - } - - callback(undefined, response?.cursor?.firstBatch[0]?.n || 0); - }); - } - - executeLegacy( - server: Server, - session: ClientSession | undefined, - callback: Callback ): void { const cmd: Document = { count: this.collectionName }; @@ -71,7 +44,7 @@ export class EstimatedDocumentCountOperation extends CommandOperation { return; } - callback(undefined, response.n || 0); + callback(undefined, response?.n || 0); }); } } diff --git a/test/integration/collection-management/collection.test.js b/test/integration/collection-management/collection.test.js index db2fbe5630..53c1278023 100644 --- a/test/integration/collection-management/collection.test.js +++ b/test/integration/collection-management/collection.test.js @@ -535,81 +535,81 @@ describe('Collection', function () { }); }); - describe('(countDocuments)', function () { + describe('#estimatedDocumentCount', function () { let client; let db; let collection; - beforeEach(function () { + + beforeEach(async function () { client = configuration.newClient({ w: 1 }); - return client.connect().then(client => { - db = client.db(configuration.db); - collection = db.collection('test_coll'); - }); - }); - afterEach(function () { - return client.close(); + await client.connect(); + db = client.db(configuration.db); + collection = db.collection('test_coll'); + await collection.insertOne({ a: 'c' }); }); - const nonMatchQueryTests = [ - { - title: 'should correctly perform estimatedDocumentCount on non-matching query' - }, - { - title: 'should correctly perform countDocuments on non-matching query' - } - ]; + afterEach(async function () { + await collection.drop(); + await client.close(); + }); - nonMatchQueryTests.forEach(test => { - it(test.title, function (done) { - const close = e => client.close(() => done(e)); - let thenFunction; - if ( - test.title === 'should correctly perform estimatedDocumentCount on non-matching query' - ) { - thenFunction = () => collection.estimatedDocumentCount({ a: 'b' }); - } else if (test.title === 'should correctly perform countDocuments on non-matching query') { - thenFunction = () => collection.countDocuments({ a: 'b' }); - } - Promise.resolve() - .then(thenFunction) - .then(count => expect(count).to.equal(0)) - .then(() => close()) - .catch(e => close(e)); - }); + it('returns the total documents in the collection', async function () { + const result = await collection.estimatedDocumentCount(); + expect(result).to.equal(1); }); + }); - it('countDocuments should return Promise that resolves when no callback passed', function (done) { - const docsPromise = collection.countDocuments(); - const close = e => client.close(() => done(e)); + describe('#countDocuments', function () { + let client; + let db; + let collection; - expect(docsPromise).to.exist.and.to.be.an.instanceof(Promise); + beforeEach(async function () { + client = configuration.newClient({ w: 1 }); + await client.connect(); + db = client.db(configuration.db); + collection = db.collection('test_coll'); + await collection.insertOne({ a: 'c' }); + }); - docsPromise - .then(result => expect(result).to.equal(0)) - .then(() => close()) - .catch(e => close(e)); + afterEach(async function () { + await collection.drop(); + await client.close(); }); - it('countDocuments should not return a promise if callback given', function (done) { - const close = e => client.close(() => done(e)); + context('when passing a non-matching query', function () { + it('returns 0', async function () { + const result = await collection.countDocuments({ a: 'b' }); + expect(result).to.equal(0); + }); + }); - const notPromise = collection.countDocuments({ a: 1 }, () => { - expect(notPromise).to.be.undefined; - close(); + context('when no callback passed', function () { + it('returns a promise', function () { + const docsPromise = collection.countDocuments(); + expect(docsPromise).to.exist.and.to.be.an.instanceof(Promise); + return docsPromise.then(result => expect(result).to.equal(1)); }); }); - it('countDocuments should correctly call the given callback', function (done) { - const docs = [{ a: 1 }, { a: 2 }]; - const close = e => client.close(() => done(e)); + context('when a callback is passed', function () { + it('does not return a promise', function (done) { + const notPromise = collection.countDocuments({ a: 1 }, () => { + expect(notPromise).to.be.undefined; + done(); + }); + }); - collection.insertMany(docs).then(() => - collection.countDocuments({ a: 1 }, (err, data) => { - expect(data).to.equal(1); - close(err); - }) - ); + it('calls the callback', function (done) { + const docs = [{ a: 1 }, { a: 2 }]; + collection.insertMany(docs).then(() => + collection.countDocuments({ a: 1 }, (err, data) => { + expect(data).to.equal(1); + done(err); + }) + ); + }); }); }); diff --git a/test/integration/read-write-concern/readconcern.test.js b/test/integration/read-write-concern/readconcern.test.js index 765ba7d8da..fa42a47b19 100644 --- a/test/integration/read-write-concern/readconcern.test.js +++ b/test/integration/read-write-concern/readconcern.test.js @@ -234,7 +234,7 @@ describe('ReadConcern', function () { done(); }); } else if (test.commandName === 'count') { - collection.estimatedDocumentCount({ a: 1 }, err => { + collection.estimatedDocumentCount(err => { expect(err).to.not.exist; validateTestResults(started, succeeded, test.commandName, test.readConcern.level); done(); diff --git a/test/spec/atlas-data-lake-testing/estimatedDocumentCount.json b/test/spec/atlas-data-lake-testing/estimatedDocumentCount.json index 87b385208d..997a3ab3fc 100644 --- a/test/spec/atlas-data-lake-testing/estimatedDocumentCount.json +++ b/test/spec/atlas-data-lake-testing/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/spec/atlas-data-lake-testing/estimatedDocumentCount.yml b/test/spec/atlas-data-lake-testing/estimatedDocumentCount.yml index 43eee2d317..64c6bbd04f 100644 --- a/test/spec/atlas-data-lake-testing/estimatedDocumentCount.yml +++ b/test/spec/atlas-data-lake-testing/estimatedDocumentCount.yml @@ -13,9 +13,6 @@ tests: - command_started_event: command: - aggregate: *collection_name - pipeline: - - $collStats: { count: {} } - - $group: { _id: 1, n: { $sum: $count }} - command_name: aggregate - database_name: *database_name + count: *collection_name + command_name: count + database_name: *database_name diff --git a/test/spec/crud/unified/estimatedDocumentCount.json b/test/spec/crud/unified/estimatedDocumentCount.json index bcd66ea954..1b650c1cb6 100644 --- a/test/spec/crud/unified/estimatedDocumentCount.json +++ b/test/spec/crud/unified/estimatedDocumentCount.json @@ -34,6 +34,13 @@ "database": "database0", "collectionName": "coll1" } + }, + { + "collection": { + "id": "collection0View", + "database": "database0", + "collectionName": "coll0view" + } } ], "initialData": [ @@ -58,12 +65,7 @@ ], "tests": [ { - "description": "estimatedDocumentCount uses $collStats on 4.9.0 or greater", - "runOnRequirements": [ - { - "minServerVersion": "4.9.0" - } - ], + "description": "estimatedDocumentCount always uses count", "operations": [ { "name": "estimatedDocumentCount", @@ -78,24 +80,9 @@ { "commandStartedEvent": { "command": { - "aggregate": "coll0", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] + "count": "coll0" }, - "commandName": "aggregate", + "commandName": "count", "databaseName": "edc-tests" } } @@ -104,12 +91,7 @@ ] }, { - "description": "estimatedDocumentCount with maxTimeMS on 4.9.0 or greater", - "runOnRequirements": [ - { - "minServerVersion": "4.9.0" - } - ], + "description": "estimatedDocumentCount with maxTimeMS", "operations": [ { "name": "estimatedDocumentCount", @@ -127,25 +109,10 @@ { "commandStartedEvent": { "command": { - "aggregate": "coll0", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ], + "count": "coll0", "maxTimeMS": 6000 }, - "commandName": "aggregate", + "commandName": "count", "databaseName": "edc-tests" } } @@ -154,12 +121,7 @@ ] }, { - "description": "estimatedDocumentCount on non-existent collection on 4.9.0 or greater", - "runOnRequirements": [ - { - "minServerVersion": "4.9.0" - } - ], + "description": "estimatedDocumentCount on non-existent collection", "operations": [ { "name": "estimatedDocumentCount", @@ -174,24 +136,9 @@ { "commandStartedEvent": { "command": { - "aggregate": "coll1", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] + "count": "coll1" }, - "commandName": "aggregate", + "commandName": "count", "databaseName": "edc-tests" } } @@ -200,78 +147,21 @@ ] }, { - "description": "estimatedDocumentCount errors correctly on 4.9.0 or greater--command error", + "description": "estimatedDocumentCount errors correctly--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 - } - } - } + "minServerVersion": "4.0.0", + "topologies": [ + "single", + "replicaset" + ] }, { - "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" - } - } + "minServerVersion": "4.2.0", + "topologies": [ + "sharded" ] } - ] - }, - { - "description": "estimatedDocumentCount errors correctly on 4.9.0 or greater--socket error", - "runOnRequirements": [ - { - "minServerVersion": "4.9.0" - } ], "operations": [ { @@ -286,9 +176,9 @@ }, "data": { "failCommands": [ - "aggregate" + "count" ], - "closeConnection": true + "errorCode": 8 } } } @@ -297,56 +187,10 @@ "name": "estimatedDocumentCount", "object": "collection0", "expectError": { - "isError": true + "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 uses count on less than 4.9.0", - "runOnRequirements": [ - { - "maxServerVersion": "4.8.99" - } - ], - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection0", - "expectResult": 3 - } - ], "expectEvents": [ { "client": "client0", @@ -365,77 +209,10 @@ ] }, { - "description": "estimatedDocumentCount with maxTimeMS on less than 4.9.0", - "runOnRequirements": [ - { - "maxServerVersion": "4.8.99" - } - ], - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection0", - "arguments": { - "maxTimeMS": 6000 - }, - "expectResult": 3 - } - ], - "expectEvents": [ - { - "client": "client0", - "events": [ - { - "commandStartedEvent": { - "command": { - "count": "coll0", - "maxTimeMS": 6000 - }, - "commandName": "count", - "databaseName": "edc-tests" - } - } - ] - } - ] - }, - { - "description": "estimatedDocumentCount on non-existent collection on less than 4.9.0", - "runOnRequirements": [ - { - "maxServerVersion": "4.8.99" - } - ], - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection1", - "expectResult": 0 - } - ], - "expectEvents": [ - { - "client": "client0", - "events": [ - { - "commandStartedEvent": { - "command": { - "count": "coll1" - }, - "commandName": "count", - "databaseName": "edc-tests" - } - } - ] - } - ] - }, - { - "description": "estimatedDocumentCount errors correctly on less than 4.9.0--command error", + "description": "estimatedDocumentCount errors correctly--socket error", "runOnRequirements": [ { "minServerVersion": "4.0.0", - "maxServerVersion": "4.8.99", "topologies": [ "single", "replicaset" @@ -443,7 +220,6 @@ }, { "minServerVersion": "4.2.0", - "maxServerVersion": "4.8.99", "topologies": [ "sharded" ] @@ -464,7 +240,7 @@ "failCommands": [ "count" ], - "errorCode": 8 + "closeConnection": true } } } @@ -473,7 +249,7 @@ "name": "estimatedDocumentCount", "object": "collection0", "expectError": { - "errorCode": 8 + "isError": true } } ], @@ -495,50 +271,41 @@ ] }, { - "description": "estimatedDocumentCount errors correctly on less than 4.9.0--socket error", + "description": "estimatedDocumentCount works correctly on views", "runOnRequirements": [ { - "minServerVersion": "4.0.0", - "maxServerVersion": "4.8.99", - "topologies": [ - "single", - "replicaset" - ] - }, - { - "minServerVersion": "4.2.0", - "maxServerVersion": "4.8.99", - "topologies": [ - "sharded" - ] + "minServerVersion": "3.4.0" } ], "operations": [ { - "name": "failPoint", - "object": "testRunner", + "name": "dropCollection", + "object": "database0", "arguments": { - "client": "client0", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "count" - ], - "closeConnection": true + "collection": "coll0view" + } + }, + { + "name": "createCollection", + "object": "database0", + "arguments": { + "collection": "coll0view", + "viewOn": "coll0", + "pipeline": [ + { + "$match": { + "_id": { + "$gt": 1 + } + } } - } + ] } }, { "name": "estimatedDocumentCount", - "object": "collection0", - "expectError": { - "isError": true - } + "object": "collection0View", + "expectResult": 2 } ], "expectEvents": [ @@ -548,7 +315,35 @@ { "commandStartedEvent": { "command": { - "count": "coll0" + "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/spec/crud/unified/estimatedDocumentCount.yml b/test/spec/crud/unified/estimatedDocumentCount.yml index c3286ec176..12f33cc7e5 100644 --- a/test/spec/crud/unified/estimatedDocumentCount.yml +++ b/test/spec/crud/unified/estimatedDocumentCount.yml @@ -21,6 +21,10 @@ createEntities: id: &collection1 collection1 database: *database0 collectionName: &collection1Name coll1 + - collection: + id: &collection0View collection0View + database: *database0 + collectionName: &collection0ViewName coll0view initialData: - collectionName: *collection0Name @@ -31,129 +35,7 @@ initialData: - { _id: 3, x: 33 } 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: *collection0Name - pipeline: &pipeline - - $collStats: { count: {} } - - $group: { _id: 1, n: { $sum: $count }} - commandName: aggregate - databaseName: *database0Name - - - 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: *collection0Name - pipeline: &pipeline - - $collStats: { count: {} } - - $group: { _id: 1, n: { $sum: $count }} - maxTimeMS: 6000 - commandName: aggregate - databaseName: *database0Name - - - 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: *collection1Name - pipeline: &pipeline - - $collStats: { count: {} } - - $group: { _id: 1, n: { $sum: $count }} - commandName: aggregate - databaseName: *database0Name - - - 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 # UnknownError - - name: estimatedDocumentCount - object: *collection0 - expectError: - errorCode: 8 # UnknownError - expectEvents: - - client: *client0 - events: - - commandStartedEvent: - command: - aggregate: *collection0Name - pipeline: &pipeline - - $collStats: { count: {} } - - $group: { _id: 1, n: { $sum: $count }} - commandName: aggregate - databaseName: *database0Name - - - 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: *collection0Name - pipeline: &pipeline - - $collStats: { count: {} } - - $group: { _id: 1, n: { $sum: $count }} - commandName: aggregate - databaseName: *database0Name - - - description: "estimatedDocumentCount uses count on less than 4.9.0" - runOnRequirements: - - maxServerVersion: "4.8.99" + - description: "estimatedDocumentCount always uses count" operations: - name: estimatedDocumentCount object: *collection0 @@ -167,9 +49,7 @@ tests: commandName: count databaseName: *database0Name - - description: "estimatedDocumentCount with maxTimeMS on less than 4.9.0" - runOnRequirements: - - maxServerVersion: "4.8.99" + - description: "estimatedDocumentCount with maxTimeMS" operations: - name: estimatedDocumentCount object: *collection0 @@ -186,9 +66,7 @@ tests: commandName: count databaseName: *database0Name - - 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 object: *collection1 @@ -202,13 +80,11 @@ tests: commandName: count databaseName: *database0Name - - 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 ] - minServerVersion: "4.2.0" - maxServerVersion: "4.8.99" topologies: [ sharded ] operations: - name: failPoint @@ -234,13 +110,11 @@ tests: commandName: count databaseName: *database0Name - - 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 ] - minServerVersion: "4.2.0" - maxServerVersion: "4.8.99" topologies: [ sharded ] operations: - name: failPoint @@ -265,3 +139,43 @@ tests: count: *collection0Name commandName: count databaseName: *database0Name + + - description: "estimatedDocumentCount works correctly on views" + # viewOn option was added to the create command in 3.4 + runOnRequirements: + - minServerVersion: "3.4.0" + operations: + - name: dropCollection + object: *database0 + arguments: + collection: *collection0ViewName + - name: createCollection + object: *database0 + arguments: + collection: *collection0ViewName + viewOn: *collection0Name + pipeline: &pipeline + - { $match: { _id: { $gt: 1 } } } + - name: estimatedDocumentCount + object: *collection0View + expectResult: 2 + expectEvents: + - client: *client0 + events: + - commandStartedEvent: + command: + drop: *collection0ViewName + commandName: drop + databaseName: *database0Name + - commandStartedEvent: + command: + create: *collection0ViewName + viewOn: *collection0Name + pipeline: *pipeline + commandName: create + databaseName: *database0Name + - commandStartedEvent: + command: + count: *collection0ViewName + commandName: count + databaseName: *database0Name diff --git a/test/spec/retryable-reads/legacy/estimatedDocumentCount-4.9.json b/test/spec/retryable-reads/legacy/estimatedDocumentCount-4.9.json deleted file mode 100644 index a4c46fc074..0000000000 --- a/test/spec/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/spec/retryable-reads/legacy/estimatedDocumentCount-4.9.yml b/test/spec/retryable-reads/legacy/estimatedDocumentCount-4.9.yml deleted file mode 100644 index 277ea010a4..0000000000 --- a/test/spec/retryable-reads/legacy/estimatedDocumentCount-4.9.yml +++ /dev/null @@ -1,60 +0,0 @@ -runOn: - - minServerVersion: "4.9.0" - -database_name: &database_name "retryable-reads-tests" -collection_name: &collection_name "coll" - -data: - - { _id: 1, x: 11 } - - { _id: 2, x: 22 } - -tests: - - - description: "EstimatedDocumentCount succeeds on first attempt" - operations: - - &retryable_operation_succeeds - <<: &retryable_operation - name: estimatedDocumentCount - object: collection - result: 2 - expectations: - - &retryable_command_started_event - command_started_event: - command: - aggregate: *collection_name - pipeline: &pipeline - - $collStats: { count: {} } - - $group: { _id: 1, n: { $sum: $count }} - database_name: *database_name - - - description: "EstimatedDocumentCount succeeds on second attempt" - failPoint: &failCommand_failPoint - configureFailPoint: failCommand - mode: { times: 1 } - data: - failCommands: [aggregate] - closeConnection: true - operations: [*retryable_operation_succeeds] - expectations: - - *retryable_command_started_event - - *retryable_command_started_event - - - description: "EstimatedDocumentCount fails on first attempt" - clientOptions: - retryReads: false - failPoint: *failCommand_failPoint - operations: - - &retryable_operation_fails - <<: *retryable_operation - error: true - expectations: - - *retryable_command_started_event - - - description: "EstimatedDocumentCount fails on second attempt" - failPoint: - <<: *failCommand_failPoint - mode: { times: 2 } - operations: [*retryable_operation_fails] - expectations: - - *retryable_command_started_event - - *retryable_command_started_event diff --git a/test/spec/retryable-reads/legacy/estimatedDocumentCount-serverErrors-4.9.json b/test/spec/retryable-reads/legacy/estimatedDocumentCount-serverErrors-4.9.json deleted file mode 100644 index 756b02b3a8..0000000000 --- a/test/spec/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/spec/retryable-reads/legacy/estimatedDocumentCount-serverErrors-4.9.yml b/test/spec/retryable-reads/legacy/estimatedDocumentCount-serverErrors-4.9.yml deleted file mode 100644 index 1a73d54312..0000000000 --- a/test/spec/retryable-reads/legacy/estimatedDocumentCount-serverErrors-4.9.yml +++ /dev/null @@ -1,146 +0,0 @@ -runOn: - - minServerVersion: "4.9.0" - -database_name: &database_name "retryable-reads-tests" -collection_name: &collection_name "coll" - -data: - - { _id: 1, x: 11 } - - { _id: 2, x: 22 } - -tests: - - - description: "EstimatedDocumentCount succeeds after InterruptedAtShutdown" - failPoint: &failCommand_failPoint - configureFailPoint: failCommand - mode: { times: 1 } - data: { failCommands: [aggregate], errorCode: 11600 } - operations: - - &retryable_operation_succeeds - <<: &retryable_operation - name: estimatedDocumentCount - object: collection - result: 2 - expectations: - - &retryable_command_started_event - command_started_event: - command: - aggregate: *collection_name - pipeline: &pipeline - - $collStats: { count: {} } - - $group: { _id: 1, n: { $sum: $count }} - database_name: *database_name - - *retryable_command_started_event - - - description: "EstimatedDocumentCount succeeds after InterruptedDueToReplStateChange" - failPoint: - <<: *failCommand_failPoint - data: { failCommands: [aggregate], errorCode: 11602 } - operations: [*retryable_operation_succeeds] - expectations: - - *retryable_command_started_event - - *retryable_command_started_event - - - description: "EstimatedDocumentCount succeeds after NotWritablePrimary" - failPoint: - <<: *failCommand_failPoint - data: { failCommands: [aggregate], errorCode: 10107 } - operations: [*retryable_operation_succeeds] - expectations: - - *retryable_command_started_event - - *retryable_command_started_event - - - description: "EstimatedDocumentCount succeeds after NotPrimaryNoSecondaryOk" - failPoint: - <<: *failCommand_failPoint - data: { failCommands: [aggregate], errorCode: 13435 } - operations: [*retryable_operation_succeeds] - expectations: - - *retryable_command_started_event - - *retryable_command_started_event - - - description: "EstimatedDocumentCount succeeds after NotPrimaryOrSecondary" - failPoint: - <<: *failCommand_failPoint - data: { failCommands: [aggregate], errorCode: 13436 } - operations: [*retryable_operation_succeeds] - expectations: - - *retryable_command_started_event - - *retryable_command_started_event - - - description: "EstimatedDocumentCount succeeds after PrimarySteppedDown" - failPoint: - <<: *failCommand_failPoint - data: { failCommands: [aggregate], errorCode: 189 } - operations: [*retryable_operation_succeeds] - expectations: - - *retryable_command_started_event - - *retryable_command_started_event - - - description: "EstimatedDocumentCount succeeds after ShutdownInProgress" - failPoint: - <<: *failCommand_failPoint - data: { failCommands: [aggregate], errorCode: 91 } - operations: [*retryable_operation_succeeds] - expectations: - - *retryable_command_started_event - - *retryable_command_started_event - - - description: "EstimatedDocumentCount succeeds after HostNotFound" - failPoint: - <<: *failCommand_failPoint - data: { failCommands: [aggregate], errorCode: 7 } - operations: [*retryable_operation_succeeds] - expectations: - - *retryable_command_started_event - - *retryable_command_started_event - - - description: "EstimatedDocumentCount succeeds after HostUnreachable" - failPoint: - <<: *failCommand_failPoint - data: { failCommands: [aggregate], errorCode: 6 } - operations: [*retryable_operation_succeeds] - expectations: - - *retryable_command_started_event - - *retryable_command_started_event - - - description: "EstimatedDocumentCount succeeds after NetworkTimeout" - failPoint: - <<: *failCommand_failPoint - data: { failCommands: [aggregate], errorCode: 89 } - operations: [*retryable_operation_succeeds] - expectations: - - *retryable_command_started_event - - *retryable_command_started_event - - - description: "EstimatedDocumentCount succeeds after SocketException" - failPoint: - <<: *failCommand_failPoint - data: { failCommands: [aggregate], errorCode: 9001 } - operations: [*retryable_operation_succeeds] - expectations: - - *retryable_command_started_event - - *retryable_command_started_event - - - description: "EstimatedDocumentCount fails after two NotWritablePrimary errors" - failPoint: - <<: *failCommand_failPoint - mode: { times: 2 } - data: { failCommands: [aggregate], errorCode: 10107 } - operations: - - &retryable_operation_fails - <<: *retryable_operation - error: true - expectations: - - *retryable_command_started_event - - *retryable_command_started_event - - - description: "EstimatedDocumentCount fails after NotWritablePrimary when retryReads is false" - clientOptions: - retryReads: false - failPoint: - <<: *failCommand_failPoint - data: { failCommands: [aggregate], errorCode: 10107 } - operations: [*retryable_operation_fails] - expectations: - - *retryable_command_started_event diff --git a/test/spec/retryable-reads/legacy/estimatedDocumentCount-serverErrors-pre4.9.json b/test/spec/retryable-reads/legacy/estimatedDocumentCount-serverErrors.json similarity index 99% rename from test/spec/retryable-reads/legacy/estimatedDocumentCount-serverErrors-pre4.9.json rename to test/spec/retryable-reads/legacy/estimatedDocumentCount-serverErrors.json index 0b9a2615d1..6bb128f5f3 100644 --- a/test/spec/retryable-reads/legacy/estimatedDocumentCount-serverErrors-pre4.9.json +++ b/test/spec/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/spec/retryable-reads/legacy/estimatedDocumentCount-serverErrors-pre4.9.yml b/test/spec/retryable-reads/legacy/estimatedDocumentCount-serverErrors.yml similarity index 98% rename from test/spec/retryable-reads/legacy/estimatedDocumentCount-serverErrors-pre4.9.yml rename to test/spec/retryable-reads/legacy/estimatedDocumentCount-serverErrors.yml index 99c343b889..aefb89ca69 100644 --- a/test/spec/retryable-reads/legacy/estimatedDocumentCount-serverErrors-pre4.9.yml +++ b/test/spec/retryable-reads/legacy/estimatedDocumentCount-serverErrors.yml @@ -1,11 +1,9 @@ runOn: - minServerVersion: "4.0" - maxServerVersion: "4.8.99" topology: ["single", "replicaset"] - minServerVersion: "4.1.7" - maxServerVersion: "4.8.99" topology: ["sharded"] database_name: &database_name "retryable-reads-tests" diff --git a/test/spec/retryable-reads/legacy/estimatedDocumentCount-pre4.9.json b/test/spec/retryable-reads/legacy/estimatedDocumentCount.json similarity index 97% rename from test/spec/retryable-reads/legacy/estimatedDocumentCount-pre4.9.json rename to test/spec/retryable-reads/legacy/estimatedDocumentCount.json index 44be966ae7..8dfa15a2cd 100644 --- a/test/spec/retryable-reads/legacy/estimatedDocumentCount-pre4.9.json +++ b/test/spec/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/spec/retryable-reads/legacy/estimatedDocumentCount-pre4.9.yml b/test/spec/retryable-reads/legacy/estimatedDocumentCount.yml similarity index 96% rename from test/spec/retryable-reads/legacy/estimatedDocumentCount-pre4.9.yml rename to test/spec/retryable-reads/legacy/estimatedDocumentCount.yml index d03a171d91..de03e483bb 100644 --- a/test/spec/retryable-reads/legacy/estimatedDocumentCount-pre4.9.yml +++ b/test/spec/retryable-reads/legacy/estimatedDocumentCount.yml @@ -1,11 +1,9 @@ runOn: - minServerVersion: "4.0" - maxServerVersion: "4.8.99" topology: ["single", "replicaset"] - minServerVersion: "4.1.7" - maxServerVersion: "4.8.99" topology: ["sharded"] database_name: &database_name "retryable-reads-tests" diff --git a/test/spec/versioned-api/crud-api-version-1-strict.json b/test/spec/versioned-api/crud-api-version-1-strict.json index 29a0ec4e3b..c1c8ecce01 100644 --- a/test/spec/versioned-api/crud-api-version-1-strict.json +++ b/test/spec/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/spec/versioned-api/crud-api-version-1-strict.yml b/test/spec/versioned-api/crud-api-version-1-strict.yml index b5f3ac2d74..17c4bee0f9 100644 --- a/test/spec/versioned-api/crud-api-version-1-strict.yml +++ b/test/spec/versioned-api/crud-api-version-1-strict.yml @@ -229,6 +229,11 @@ tests: <<: *expectedApiVersion - description: "estimatedDocumentCount appends declared API version" + # See: https://jira.mongodb.org/browse/SERVER-63850 + runOnRequirements: + - minServerVersion: "5.0.9" + maxServerVersion: "5.0.99" + - minServerVersion: "5.3.2" operations: - name: estimatedDocumentCount object: *collection @@ -238,10 +243,7 @@ tests: events: - commandStartedEvent: command: - aggregate: *collectionName - pipeline: &pipeline - - $collStats: { count: {} } - - $group: { _id: 1, n: { $sum: $count }} + count: *collectionName <<: *expectedApiVersion - description: "find and getMore append API version" diff --git a/test/spec/versioned-api/crud-api-version-1.json b/test/spec/versioned-api/crud-api-version-1.json index 1f135eea18..a387d0587e 100644 --- a/test/spec/versioned-api/crud-api-version-1.json +++ b/test/spec/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 diff --git a/test/spec/versioned-api/crud-api-version-1.yml b/test/spec/versioned-api/crud-api-version-1.yml index d2fb5b9130..50135c1458 100644 --- a/test/spec/versioned-api/crud-api-version-1.yml +++ b/test/spec/versioned-api/crud-api-version-1.yml @@ -222,7 +222,12 @@ tests: key: x <<: *expectedApiVersion - - description: "estimatedDocumentCount appends declared API version on 4.9.0 or greater" + - description: "estimatedDocumentCount appends declared API version" + # See: https://jira.mongodb.org/browse/SERVER-63850 + runOnRequirements: + - minServerVersion: "5.0.9" + maxServerVersion: "5.0.99" + - minServerVersion: "5.3.2" operations: - name: estimatedDocumentCount object: *collection @@ -232,10 +237,7 @@ tests: events: - commandStartedEvent: command: - aggregate: *collectionName - pipeline: &pipeline - - $collStats: { count: {} } - - $group: { _id: 1, n: { $sum: $count }} + count: *collectionName <<: *expectedApiVersion - description: "find and getMore append API version"