From 7596d03a0177217323201c227420004272cd0ba6 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Fri, 3 Mar 2023 09:44:45 -0500 Subject: [PATCH 1/2] Add TS types for Mongo Collection countDocuments and estimatedDocumentCount Types were missing but both methods are implemented in `collection.js` and documented here: https://docs.meteor.com/api/collections.html#Mongo-Collection-countDocuments Also, `estimatedDocumentCount` does not take a selector as parameter. See: * https://www.mongodb.com/docs/drivers/node/current/usage-examples/count/ * https://mongodb.github.io/node-mongodb-native/5.1/classes/Collection.html#estimatedDocumentCount --- packages/mongo/collection.js | 1 - packages/mongo/mongo.d.ts | 11 +++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/mongo/collection.js b/packages/mongo/collection.js index d5b99edae4..d0a28f4e20 100644 --- a/packages/mongo/collection.js +++ b/packages/mongo/collection.js @@ -339,7 +339,6 @@ Object.assign(Mongo.Collection.prototype, { * @method estimatedDocumentCount * @memberof Mongo.Collection * @instance - * @param {MongoSelector} [selector] A query describing the documents to count * @param {Object} [options] All options are listed in [MongoDB documentation](https://mongodb.github.io/node-mongodb-native/4.11/interfaces/EstimatedDocumentCountOptions.html). Please note that not all of them are available on the client. * @returns {Promise} */ diff --git a/packages/mongo/mongo.d.ts b/packages/mongo/mongo.d.ts index 6445823a73..1b5fca29a1 100644 --- a/packages/mongo/mongo.d.ts +++ b/packages/mongo/mongo.d.ts @@ -195,6 +195,17 @@ export namespace Mongo { selector?: Selector | ObjectID | string, options?: O ): Promise | undefined>; + /** + * Gets the number of documents matching the filter. For a fast count of the total documents in a collection see `estimatedDocumentCount`. + * @param selector The query for filtering the set of documents to count + * @param options All options are listed in [MongoDB documentation](https://mongodb.github.io/node-mongodb-native/4.11/interfaces/CountDocumentsOptions.html). Please note that not all of them are available on the client. + */ + countDocuments(selector?: Selector | ObjectID | string, options?: MongoNpmModule.CountDocumentsOptions): Promise; + /** + * Gets an estimate of the count of documents in a collection using collection metadata. For an exact count of the documents in a collection see `countDocuments`. + * @param options All options are listed in [MongoDB documentation](https://mongodb.github.io/node-mongodb-native/4.11/interfaces/CountDocumentsOptions.html). Please note that not all of them are available on the client. + */ + estimatedDocumentCount(options: MongoNpmModule.EstimatedDocumentCountOptions): Promise; /** * Insert a document in the collection. Returns its unique _id. * @param doc The document to insert. May not yet have an _id attribute, in which case Meteor will generate one for you. From 1447ac18c7be93c6faf068a08f7ce38ad820b387 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Mon, 6 Mar 2023 08:30:06 -0500 Subject: [PATCH 2/2] Update packages/mongo/mongo.d.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Radosław Miernik --- packages/mongo/mongo.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/mongo/mongo.d.ts b/packages/mongo/mongo.d.ts index 1b5fca29a1..ccaa724852 100644 --- a/packages/mongo/mongo.d.ts +++ b/packages/mongo/mongo.d.ts @@ -205,7 +205,7 @@ export namespace Mongo { * Gets an estimate of the count of documents in a collection using collection metadata. For an exact count of the documents in a collection see `countDocuments`. * @param options All options are listed in [MongoDB documentation](https://mongodb.github.io/node-mongodb-native/4.11/interfaces/CountDocumentsOptions.html). Please note that not all of them are available on the client. */ - estimatedDocumentCount(options: MongoNpmModule.EstimatedDocumentCountOptions): Promise; + estimatedDocumentCount(options?: MongoNpmModule.EstimatedDocumentCountOptions): Promise; /** * Insert a document in the collection. Returns its unique _id. * @param doc The document to insert. May not yet have an _id attribute, in which case Meteor will generate one for you.