From 4fa4ba6bd1bb1a29ffa36c65ec0e65573d5af76f Mon Sep 17 00:00:00 2001 From: Youri Tolstoy Date: Wed, 13 Jun 2018 23:12:49 +0200 Subject: [PATCH 1/2] Expose Aggregate.count(countName) method The Aggregate class should expose a `count(countName)` method that adds a `$count` aggregator in the pipeline. Documented here: http://mongoosejs.com/docs/api.html#aggregate_Aggregate-count Code @5.0.15 referencing this method: https://github.com/Automattic/mongoose/blob/5.0.15/lib/aggregate.js#L379 --- types/mongoose/index.d.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/types/mongoose/index.d.ts b/types/mongoose/index.d.ts index a94f3a691d..ba0e6344cb 100644 --- a/types/mongoose/index.d.ts +++ b/types/mongoose/index.d.ts @@ -2274,6 +2274,12 @@ declare module "mongoose" { /** Adds a collation. */ collation(options: CollationOptions): this; + /** + * Appends a new $count operator to this aggregate pipeline. + * @param countName name of the count field + */ + count(countName: string): this; + /** * Sets the cursor option option for the aggregation query (ignored for < 2.6.0). * Note the different syntax below: .exec() returns a cursor object, and no callback From 8f5a8c1c69d51cd9bfb9ef8d9818bacdcac0fd1b Mon Sep 17 00:00:00 2001 From: Youri Tolstoy Date: Wed, 13 Jun 2018 23:18:58 +0200 Subject: [PATCH 2/2] Add test for aggregate.count() --- types/mongoose/mongoose-tests.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/mongoose/mongoose-tests.ts b/types/mongoose/mongoose-tests.ts index 90259483f2..796ae086e3 100644 --- a/types/mongoose/mongoose-tests.ts +++ b/types/mongoose/mongoose-tests.ts @@ -1200,6 +1200,7 @@ aggregate.allowDiskUse(true).allowDiskUse(false, []); aggregate.append({ $project: { field: 1 }}, { $limit: 2 }); aggregate.append([{ $match: { daw: 'Logic Audio X' }} ]); aggregate.collation({ locale: 'en_US', strength: 1 }); +aggregate.count('countName'); aggregate.cursor({ batchSize: 1000 }).exec().each(cb); aggregate.exec().then(cb).catch(cb); aggregate.option({foo: 'bar'}).exec();