collection.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.Collection = void 0;
  4. const bson_1 = require("./bson");
  5. const ordered_1 = require("./bulk/ordered");
  6. const unordered_1 = require("./bulk/unordered");
  7. const change_stream_1 = require("./change_stream");
  8. const aggregation_cursor_1 = require("./cursor/aggregation_cursor");
  9. const find_cursor_1 = require("./cursor/find_cursor");
  10. const error_1 = require("./error");
  11. const bulk_write_1 = require("./operations/bulk_write");
  12. const count_documents_1 = require("./operations/count_documents");
  13. const delete_1 = require("./operations/delete");
  14. const distinct_1 = require("./operations/distinct");
  15. const drop_1 = require("./operations/drop");
  16. const estimated_document_count_1 = require("./operations/estimated_document_count");
  17. const execute_operation_1 = require("./operations/execute_operation");
  18. const find_and_modify_1 = require("./operations/find_and_modify");
  19. const indexes_1 = require("./operations/indexes");
  20. const insert_1 = require("./operations/insert");
  21. const is_capped_1 = require("./operations/is_capped");
  22. const map_reduce_1 = require("./operations/map_reduce");
  23. const options_operation_1 = require("./operations/options_operation");
  24. const rename_1 = require("./operations/rename");
  25. const stats_1 = require("./operations/stats");
  26. const update_1 = require("./operations/update");
  27. const read_concern_1 = require("./read_concern");
  28. const read_preference_1 = require("./read_preference");
  29. const utils_1 = require("./utils");
  30. const write_concern_1 = require("./write_concern");
  31. /**
  32. * The **Collection** class is an internal class that embodies a MongoDB collection
  33. * allowing for insert/update/remove/find and other command operation on that MongoDB collection.
  34. *
  35. * **COLLECTION Cannot directly be instantiated**
  36. * @public
  37. *
  38. * @example
  39. * ```js
  40. * const MongoClient = require('mongodb').MongoClient;
  41. * const test = require('assert');
  42. * // Connection url
  43. * const url = 'mongodb://localhost:27017';
  44. * // Database Name
  45. * const dbName = 'test';
  46. * // Connect using MongoClient
  47. * MongoClient.connect(url, function(err, client) {
  48. * // Create a collection we want to drop later
  49. * const col = client.db(dbName).collection('createIndexExample1');
  50. * // Show that duplicate records got dropped
  51. * col.find({}).toArray(function(err, items) {
  52. * expect(err).to.not.exist;
  53. * test.equal(4, items.length);
  54. * client.close();
  55. * });
  56. * });
  57. * ```
  58. */
  59. class Collection {
  60. /**
  61. * Create a new Collection instance
  62. * @internal
  63. */
  64. constructor(db, name, options) {
  65. var _a, _b;
  66. (0, utils_1.checkCollectionName)(name);
  67. // Internal state
  68. this.s = {
  69. db,
  70. options,
  71. namespace: new utils_1.MongoDBNamespace(db.databaseName, name),
  72. pkFactory: (_b = (_a = db.options) === null || _a === void 0 ? void 0 : _a.pkFactory) !== null && _b !== void 0 ? _b : utils_1.DEFAULT_PK_FACTORY,
  73. readPreference: read_preference_1.ReadPreference.fromOptions(options),
  74. bsonOptions: (0, bson_1.resolveBSONOptions)(options, db),
  75. readConcern: read_concern_1.ReadConcern.fromOptions(options),
  76. writeConcern: write_concern_1.WriteConcern.fromOptions(options)
  77. };
  78. }
  79. /**
  80. * The name of the database this collection belongs to
  81. */
  82. get dbName() {
  83. return this.s.namespace.db;
  84. }
  85. /**
  86. * The name of this collection
  87. */
  88. get collectionName() {
  89. // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
  90. return this.s.namespace.collection;
  91. }
  92. /**
  93. * The namespace of this collection, in the format `${this.dbName}.${this.collectionName}`
  94. */
  95. get namespace() {
  96. return this.s.namespace.toString();
  97. }
  98. /**
  99. * The current readConcern of the collection. If not explicitly defined for
  100. * this collection, will be inherited from the parent DB
  101. */
  102. get readConcern() {
  103. if (this.s.readConcern == null) {
  104. return this.s.db.readConcern;
  105. }
  106. return this.s.readConcern;
  107. }
  108. /**
  109. * The current readPreference of the collection. If not explicitly defined for
  110. * this collection, will be inherited from the parent DB
  111. */
  112. get readPreference() {
  113. if (this.s.readPreference == null) {
  114. return this.s.db.readPreference;
  115. }
  116. return this.s.readPreference;
  117. }
  118. get bsonOptions() {
  119. return this.s.bsonOptions;
  120. }
  121. /**
  122. * The current writeConcern of the collection. If not explicitly defined for
  123. * this collection, will be inherited from the parent DB
  124. */
  125. get writeConcern() {
  126. if (this.s.writeConcern == null) {
  127. return this.s.db.writeConcern;
  128. }
  129. return this.s.writeConcern;
  130. }
  131. /** The current index hint for the collection */
  132. get hint() {
  133. return this.s.collectionHint;
  134. }
  135. set hint(v) {
  136. this.s.collectionHint = (0, utils_1.normalizeHintField)(v);
  137. }
  138. insertOne(doc, options, callback) {
  139. if (typeof options === 'function') {
  140. callback = options;
  141. options = {};
  142. }
  143. // CSFLE passes in { w: 'majority' } to ensure the lib works in both 3.x and 4.x
  144. // we support that option style here only
  145. if (options && Reflect.get(options, 'w')) {
  146. options.writeConcern = write_concern_1.WriteConcern.fromOptions(Reflect.get(options, 'w'));
  147. }
  148. return (0, execute_operation_1.executeOperation)((0, utils_1.getTopology)(this), new insert_1.InsertOneOperation(this, doc, (0, utils_1.resolveOptions)(this, options)), callback);
  149. }
  150. insertMany(docs, options, callback) {
  151. if (typeof options === 'function')
  152. (callback = options), (options = {});
  153. options = options ? Object.assign({}, options) : { ordered: true };
  154. return (0, execute_operation_1.executeOperation)((0, utils_1.getTopology)(this), new insert_1.InsertManyOperation(this, docs, (0, utils_1.resolveOptions)(this, options)), callback);
  155. }
  156. bulkWrite(operations, options, callback) {
  157. if (typeof options === 'function')
  158. (callback = options), (options = {});
  159. options = options || { ordered: true };
  160. if (!Array.isArray(operations)) {
  161. throw new error_1.MongoInvalidArgumentError('Argument "operations" must be an array of documents');
  162. }
  163. return (0, execute_operation_1.executeOperation)((0, utils_1.getTopology)(this), new bulk_write_1.BulkWriteOperation(this, operations, (0, utils_1.resolveOptions)(this, options)), callback);
  164. }
  165. updateOne(filter, update, options, callback) {
  166. if (typeof options === 'function')
  167. (callback = options), (options = {});
  168. return (0, execute_operation_1.executeOperation)((0, utils_1.getTopology)(this), new update_1.UpdateOneOperation(this, filter, update, (0, utils_1.resolveOptions)(this, options)), callback);
  169. }
  170. replaceOne(filter, replacement, options, callback) {
  171. if (typeof options === 'function')
  172. (callback = options), (options = {});
  173. return (0, execute_operation_1.executeOperation)((0, utils_1.getTopology)(this), new update_1.ReplaceOneOperation(this, filter, replacement, (0, utils_1.resolveOptions)(this, options)), callback);
  174. }
  175. updateMany(filter, update, options, callback) {
  176. if (typeof options === 'function')
  177. (callback = options), (options = {});
  178. return (0, execute_operation_1.executeOperation)((0, utils_1.getTopology)(this), new update_1.UpdateManyOperation(this, filter, update, (0, utils_1.resolveOptions)(this, options)), callback);
  179. }
  180. deleteOne(filter, options, callback) {
  181. if (typeof options === 'function')
  182. (callback = options), (options = {});
  183. return (0, execute_operation_1.executeOperation)((0, utils_1.getTopology)(this), new delete_1.DeleteOneOperation(this, filter, (0, utils_1.resolveOptions)(this, options)), callback);
  184. }
  185. deleteMany(filter, options, callback) {
  186. if (filter == null) {
  187. filter = {};
  188. options = {};
  189. callback = undefined;
  190. }
  191. else if (typeof filter === 'function') {
  192. callback = filter;
  193. filter = {};
  194. options = {};
  195. }
  196. else if (typeof options === 'function') {
  197. callback = options;
  198. options = {};
  199. }
  200. return (0, execute_operation_1.executeOperation)((0, utils_1.getTopology)(this), new delete_1.DeleteManyOperation(this, filter, (0, utils_1.resolveOptions)(this, options)), callback);
  201. }
  202. rename(newName, options, callback) {
  203. if (typeof options === 'function')
  204. (callback = options), (options = {});
  205. // Intentionally, we do not inherit options from parent for this operation.
  206. return (0, execute_operation_1.executeOperation)((0, utils_1.getTopology)(this), new rename_1.RenameOperation(this, newName, {
  207. ...options,
  208. readPreference: read_preference_1.ReadPreference.PRIMARY
  209. }), callback);
  210. }
  211. drop(options, callback) {
  212. if (typeof options === 'function')
  213. (callback = options), (options = {});
  214. options = options !== null && options !== void 0 ? options : {};
  215. return (0, execute_operation_1.executeOperation)((0, utils_1.getTopology)(this), new drop_1.DropCollectionOperation(this.s.db, this.collectionName, options), callback);
  216. }
  217. findOne(filter, options, callback) {
  218. if (callback != null && typeof callback !== 'function') {
  219. throw new error_1.MongoInvalidArgumentError('Third parameter to `findOne()` must be a callback or undefined');
  220. }
  221. if (typeof filter === 'function') {
  222. callback = filter;
  223. filter = {};
  224. options = {};
  225. }
  226. if (typeof options === 'function') {
  227. callback = options;
  228. options = {};
  229. }
  230. const finalFilter = filter !== null && filter !== void 0 ? filter : {};
  231. const finalOptions = options !== null && options !== void 0 ? options : {};
  232. return this.find(finalFilter, finalOptions).limit(-1).batchSize(1).next(callback);
  233. }
  234. find(filter, options) {
  235. if (arguments.length > 2) {
  236. throw new error_1.MongoInvalidArgumentError('Method "collection.find()" accepts at most two arguments');
  237. }
  238. if (typeof options === 'function') {
  239. throw new error_1.MongoInvalidArgumentError('Argument "options" must not be function');
  240. }
  241. return new find_cursor_1.FindCursor((0, utils_1.getTopology)(this), this.s.namespace, filter, (0, utils_1.resolveOptions)(this, options));
  242. }
  243. options(options, callback) {
  244. if (typeof options === 'function')
  245. (callback = options), (options = {});
  246. return (0, execute_operation_1.executeOperation)((0, utils_1.getTopology)(this), new options_operation_1.OptionsOperation(this, (0, utils_1.resolveOptions)(this, options)), callback);
  247. }
  248. isCapped(options, callback) {
  249. if (typeof options === 'function')
  250. (callback = options), (options = {});
  251. return (0, execute_operation_1.executeOperation)((0, utils_1.getTopology)(this), new is_capped_1.IsCappedOperation(this, (0, utils_1.resolveOptions)(this, options)), callback);
  252. }
  253. createIndex(indexSpec, options, callback) {
  254. if (typeof options === 'function')
  255. (callback = options), (options = {});
  256. return (0, execute_operation_1.executeOperation)((0, utils_1.getTopology)(this), new indexes_1.CreateIndexOperation(this, this.collectionName, indexSpec, (0, utils_1.resolveOptions)(this, options)), callback);
  257. }
  258. createIndexes(indexSpecs, options, callback) {
  259. if (typeof options === 'function')
  260. (callback = options), (options = {});
  261. options = options ? Object.assign({}, options) : {};
  262. if (typeof options.maxTimeMS !== 'number')
  263. delete options.maxTimeMS;
  264. return (0, execute_operation_1.executeOperation)((0, utils_1.getTopology)(this), new indexes_1.CreateIndexesOperation(this, this.collectionName, indexSpecs, (0, utils_1.resolveOptions)(this, options)), callback);
  265. }
  266. dropIndex(indexName, options, callback) {
  267. if (typeof options === 'function')
  268. (callback = options), (options = {});
  269. options = (0, utils_1.resolveOptions)(this, options);
  270. // Run only against primary
  271. options.readPreference = read_preference_1.ReadPreference.primary;
  272. return (0, execute_operation_1.executeOperation)((0, utils_1.getTopology)(this), new indexes_1.DropIndexOperation(this, indexName, options), callback);
  273. }
  274. dropIndexes(options, callback) {
  275. if (typeof options === 'function')
  276. (callback = options), (options = {});
  277. return (0, execute_operation_1.executeOperation)((0, utils_1.getTopology)(this), new indexes_1.DropIndexesOperation(this, (0, utils_1.resolveOptions)(this, options)), callback);
  278. }
  279. /**
  280. * Get the list of all indexes information for the collection.
  281. *
  282. * @param options - Optional settings for the command
  283. */
  284. listIndexes(options) {
  285. return new indexes_1.ListIndexesCursor(this, (0, utils_1.resolveOptions)(this, options));
  286. }
  287. indexExists(indexes, options, callback) {
  288. if (typeof options === 'function')
  289. (callback = options), (options = {});
  290. return (0, execute_operation_1.executeOperation)((0, utils_1.getTopology)(this), new indexes_1.IndexExistsOperation(this, indexes, (0, utils_1.resolveOptions)(this, options)), callback);
  291. }
  292. indexInformation(options, callback) {
  293. if (typeof options === 'function')
  294. (callback = options), (options = {});
  295. return (0, execute_operation_1.executeOperation)((0, utils_1.getTopology)(this), new indexes_1.IndexInformationOperation(this.s.db, this.collectionName, (0, utils_1.resolveOptions)(this, options)), callback);
  296. }
  297. estimatedDocumentCount(options, callback) {
  298. if (typeof options === 'function')
  299. (callback = options), (options = {});
  300. return (0, execute_operation_1.executeOperation)((0, utils_1.getTopology)(this), new estimated_document_count_1.EstimatedDocumentCountOperation(this, (0, utils_1.resolveOptions)(this, options)), callback);
  301. }
  302. countDocuments(filter, options, callback) {
  303. if (filter == null) {
  304. (filter = {}), (options = {}), (callback = undefined);
  305. }
  306. else if (typeof filter === 'function') {
  307. (callback = filter), (filter = {}), (options = {});
  308. }
  309. else {
  310. if (arguments.length === 2) {
  311. if (typeof options === 'function')
  312. (callback = options), (options = {});
  313. }
  314. }
  315. filter !== null && filter !== void 0 ? filter : (filter = {});
  316. return (0, execute_operation_1.executeOperation)((0, utils_1.getTopology)(this), new count_documents_1.CountDocumentsOperation(this, filter, (0, utils_1.resolveOptions)(this, options)), callback);
  317. }
  318. // Implementation
  319. distinct(key, filter, options, callback) {
  320. if (typeof filter === 'function') {
  321. (callback = filter), (filter = {}), (options = {});
  322. }
  323. else {
  324. if (arguments.length === 3 && typeof options === 'function') {
  325. (callback = options), (options = {});
  326. }
  327. }
  328. filter !== null && filter !== void 0 ? filter : (filter = {});
  329. return (0, execute_operation_1.executeOperation)((0, utils_1.getTopology)(this), new distinct_1.DistinctOperation(this, key, filter, (0, utils_1.resolveOptions)(this, options)), callback);
  330. }
  331. indexes(options, callback) {
  332. if (typeof options === 'function')
  333. (callback = options), (options = {});
  334. return (0, execute_operation_1.executeOperation)((0, utils_1.getTopology)(this), new indexes_1.IndexesOperation(this, (0, utils_1.resolveOptions)(this, options)), callback);
  335. }
  336. stats(options, callback) {
  337. if (typeof options === 'function')
  338. (callback = options), (options = {});
  339. options = options !== null && options !== void 0 ? options : {};
  340. return (0, execute_operation_1.executeOperation)((0, utils_1.getTopology)(this), new stats_1.CollStatsOperation(this, options), callback);
  341. }
  342. findOneAndDelete(filter, options, callback) {
  343. if (typeof options === 'function')
  344. (callback = options), (options = {});
  345. return (0, execute_operation_1.executeOperation)((0, utils_1.getTopology)(this), new find_and_modify_1.FindOneAndDeleteOperation(this, filter, (0, utils_1.resolveOptions)(this, options)), callback);
  346. }
  347. findOneAndReplace(filter, replacement, options, callback) {
  348. if (typeof options === 'function')
  349. (callback = options), (options = {});
  350. return (0, execute_operation_1.executeOperation)((0, utils_1.getTopology)(this), new find_and_modify_1.FindOneAndReplaceOperation(this, filter, replacement, (0, utils_1.resolveOptions)(this, options)), callback);
  351. }
  352. findOneAndUpdate(filter, update, options, callback) {
  353. if (typeof options === 'function')
  354. (callback = options), (options = {});
  355. return (0, execute_operation_1.executeOperation)((0, utils_1.getTopology)(this), new find_and_modify_1.FindOneAndUpdateOperation(this, filter, update, (0, utils_1.resolveOptions)(this, options)), callback);
  356. }
  357. /**
  358. * Execute an aggregation framework pipeline against the collection, needs MongoDB \>= 2.2
  359. *
  360. * @param pipeline - An array of aggregation pipelines to execute
  361. * @param options - Optional settings for the command
  362. */
  363. aggregate(pipeline = [], options) {
  364. if (arguments.length > 2) {
  365. throw new error_1.MongoInvalidArgumentError('Method "collection.aggregate()" accepts at most two arguments');
  366. }
  367. if (!Array.isArray(pipeline)) {
  368. throw new error_1.MongoInvalidArgumentError('Argument "pipeline" must be an array of aggregation stages');
  369. }
  370. if (typeof options === 'function') {
  371. throw new error_1.MongoInvalidArgumentError('Argument "options" must not be function');
  372. }
  373. return new aggregation_cursor_1.AggregationCursor((0, utils_1.getTopology)(this), this.s.namespace, pipeline, (0, utils_1.resolveOptions)(this, options));
  374. }
  375. /**
  376. * Create a new Change Stream, watching for new changes (insertions, updates, replacements, deletions, and invalidations) in this collection.
  377. *
  378. * @since 3.0.0
  379. * @param pipeline - An array of {@link https://docs.mongodb.com/manual/reference/operator/aggregation-pipeline/|aggregation pipeline stages} through which to pass change stream documents. This allows for filtering (using $match) and manipulating the change stream documents.
  380. * @param options - Optional settings for the command
  381. */
  382. watch(pipeline = [], options = {}) {
  383. // Allow optionally not specifying a pipeline
  384. if (!Array.isArray(pipeline)) {
  385. options = pipeline;
  386. pipeline = [];
  387. }
  388. return new change_stream_1.ChangeStream(this, pipeline, (0, utils_1.resolveOptions)(this, options));
  389. }
  390. mapReduce(map, reduce, options, callback) {
  391. (0, utils_1.emitWarningOnce)('collection.mapReduce is deprecated. Use the aggregation pipeline instead. Visit https://docs.mongodb.com/manual/reference/map-reduce-to-aggregation-pipeline for more information on how to translate map-reduce operations to the aggregation pipeline.');
  392. if ('function' === typeof options)
  393. (callback = options), (options = {});
  394. // Out must always be defined (make sure we don't break weirdly on pre 1.8+ servers)
  395. // TODO NODE-3339: Figure out if this is still necessary given we no longer officially support pre-1.8
  396. if ((options === null || options === void 0 ? void 0 : options.out) == null) {
  397. throw new error_1.MongoInvalidArgumentError('Option "out" must be defined, see mongodb docs for possible values');
  398. }
  399. if ('function' === typeof map) {
  400. map = map.toString();
  401. }
  402. if ('function' === typeof reduce) {
  403. reduce = reduce.toString();
  404. }
  405. if ('function' === typeof options.finalize) {
  406. options.finalize = options.finalize.toString();
  407. }
  408. return (0, execute_operation_1.executeOperation)((0, utils_1.getTopology)(this), new map_reduce_1.MapReduceOperation(this, map, reduce, (0, utils_1.resolveOptions)(this, options)), callback);
  409. }
  410. /** Initiate an Out of order batch write operation. All operations will be buffered into insert/update/remove commands executed out of order. */
  411. initializeUnorderedBulkOp(options) {
  412. return new unordered_1.UnorderedBulkOperation(this, (0, utils_1.resolveOptions)(this, options));
  413. }
  414. /** Initiate an In order bulk write operation. Operations will be serially executed in the order they are added, creating a new operation for each switch in types. */
  415. initializeOrderedBulkOp(options) {
  416. return new ordered_1.OrderedBulkOperation(this, (0, utils_1.resolveOptions)(this, options));
  417. }
  418. /** Get the db scoped logger */
  419. getLogger() {
  420. return this.s.db.s.logger;
  421. }
  422. get logger() {
  423. return this.s.db.s.logger;
  424. }
  425. /**
  426. * Inserts a single document or a an array of documents into MongoDB. If documents passed in do not contain the **_id** field,
  427. * one will be added to each of the documents missing it by the driver, mutating the document. This behavior
  428. * can be overridden by setting the **forceServerObjectId** flag.
  429. *
  430. * @deprecated Use insertOne, insertMany or bulkWrite instead.
  431. * @param docs - The documents to insert
  432. * @param options - Optional settings for the command
  433. * @param callback - An optional callback, a Promise will be returned if none is provided
  434. */
  435. insert(docs, options, callback) {
  436. (0, utils_1.emitWarningOnce)('collection.insert is deprecated. Use insertOne, insertMany or bulkWrite instead.');
  437. if (typeof options === 'function')
  438. (callback = options), (options = {});
  439. options = options || { ordered: false };
  440. docs = !Array.isArray(docs) ? [docs] : docs;
  441. if (options.keepGoing === true) {
  442. options.ordered = false;
  443. }
  444. return this.insertMany(docs, options, callback);
  445. }
  446. /**
  447. * Updates documents.
  448. *
  449. * @deprecated use updateOne, updateMany or bulkWrite
  450. * @param selector - The selector for the update operation.
  451. * @param update - The update operations to be applied to the documents
  452. * @param options - Optional settings for the command
  453. * @param callback - An optional callback, a Promise will be returned if none is provided
  454. */
  455. update(selector, update, options, callback) {
  456. (0, utils_1.emitWarningOnce)('collection.update is deprecated. Use updateOne, updateMany, or bulkWrite instead.');
  457. if (typeof options === 'function')
  458. (callback = options), (options = {});
  459. options = options !== null && options !== void 0 ? options : {};
  460. return this.updateMany(selector, update, options, callback);
  461. }
  462. /**
  463. * Remove documents.
  464. *
  465. * @deprecated use deleteOne, deleteMany or bulkWrite
  466. * @param selector - The selector for the update operation.
  467. * @param options - Optional settings for the command
  468. * @param callback - An optional callback, a Promise will be returned if none is provided
  469. */
  470. remove(selector, options, callback) {
  471. (0, utils_1.emitWarningOnce)('collection.remove is deprecated. Use deleteOne, deleteMany, or bulkWrite instead.');
  472. if (typeof options === 'function')
  473. (callback = options), (options = {});
  474. options = options !== null && options !== void 0 ? options : {};
  475. return this.deleteMany(selector, options, callback);
  476. }
  477. count(filter, options, callback) {
  478. if (typeof filter === 'function') {
  479. (callback = filter), (filter = {}), (options = {});
  480. }
  481. else {
  482. if (typeof options === 'function')
  483. (callback = options), (options = {});
  484. }
  485. filter !== null && filter !== void 0 ? filter : (filter = {});
  486. return (0, execute_operation_1.executeOperation)((0, utils_1.getTopology)(this), new count_documents_1.CountDocumentsOperation(this, filter, (0, utils_1.resolveOptions)(this, options)), callback);
  487. }
  488. }
  489. exports.Collection = Collection;
  490. //# sourceMappingURL=collection.js.map