Skip to content

Commit 28ca63a

Browse files
mbroadstdaprahamian
authored andcommitted
refact: reused EstimatedDocumentCountOperation for depd count
1 parent caaa9aa commit 28ca63a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lib/collection.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ const CommandCursor = require('./command_cursor');
2626

2727
// Operations
2828
const checkForAtomicOperators = require('./operations/collection_ops').checkForAtomicOperators;
29-
const count = require('./operations/collection_ops').count;
3029
const ensureIndex = require('./operations/collection_ops').ensureIndex;
3130
const findAndModify = require('./operations/collection_ops').findAndModify;
3231
const findAndRemove = require('./operations/collection_ops').findAndRemove;
@@ -1369,9 +1368,16 @@ Collection.prototype.count = deprecate(function(query, options, callback) {
13691368
query = args.length ? args.shift() || {} : {};
13701369
options = args.length ? args.shift() || {} : {};
13711370

1372-
return executeLegacyOperation(this.s.topology, count, [this, query, options, callback]);
1371+
if (typeof options === 'function') (callback = options), (options = {});
1372+
options = options || {};
1373+
1374+
return executeOperation(
1375+
this.s.topology,
1376+
new EstimatedDocumentCountOperation(this, query, options),
1377+
callback
1378+
);
13731379
}, 'collection.count is deprecated, and will be removed in a future version.' +
1374-
' Use collection.countDocuments or collection.estimatedDocumentCount instead');
1380+
' Use Collection.countDocuments or Collection.estimatedDocumentCount instead');
13751381

13761382
/**
13771383
* Gets an estimate of the count of documents in a collection using collection metadata.

0 commit comments

Comments
 (0)