Skip to content

Commit 2e44de6

Browse files
committed
feat(NODE-4079): estimated document count uses count
1 parent 922412f commit 2e44de6

7 files changed

+168
-468
lines changed

src/operations/estimated_document_count.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ export class EstimatedDocumentCountOperation extends CommandOperation<number> {
3636
if (maxWireVersion(server) < 12) {
3737
return this.executeLegacy(server, session, callback);
3838
}
39-
const pipeline = [{ $collStats: { count: {} } }, { $group: { _id: 1, n: { $sum: '$count' } } }];
4039

41-
const cmd: Document = { aggregate: this.collectionName, pipeline, cursor: {} };
40+
const cmd: Document = { count: this.collectionName };
4241

4342
if (typeof this.options.maxTimeMS === 'number') {
4443
cmd.maxTimeMS = this.options.maxTimeMS;
@@ -50,7 +49,7 @@ export class EstimatedDocumentCountOperation extends CommandOperation<number> {
5049
return;
5150
}
5251

53-
callback(undefined, response?.cursor?.firstBatch[0]?.n || 0);
52+
callback(undefined, response?.n || 0);
5453
});
5554
}
5655

0 commit comments

Comments
 (0)