Skip to content

Commit

Permalink
feat(NODE-4079): estimated document count uses count
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed May 11, 2022
1 parent 15f8870 commit bfbe11b
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 468 deletions.
5 changes: 2 additions & 3 deletions src/operations/estimated_document_count.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ export class EstimatedDocumentCountOperation extends CommandOperation<number> {
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: {} };
const cmd: Document = { count: this.collectionName };

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

callback(undefined, response?.cursor?.firstBatch[0]?.n || 0);
callback(undefined, response?.n || 0);
});
}

Expand Down

0 comments on commit bfbe11b

Please sign in to comment.