From 30661bcb496505dc0bf489810eaeb3f206a91faa Mon Sep 17 00:00:00 2001 From: Alexandr Ni Date: Fri, 31 Aug 2018 17:25:46 -0400 Subject: [PATCH 1/2] Facet function for mongoose aggregate --- types/mongoose/index.d.ts | 8 +++++++- types/mongoose/mongoose-tests.ts | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/types/mongoose/index.d.ts b/types/mongoose/index.d.ts index 94aacd244e..cd2da11312 100644 --- a/types/mongoose/index.d.ts +++ b/types/mongoose/index.d.ts @@ -2336,13 +2336,19 @@ declare module "mongoose" { */ cursor(options: any): this; + /** + * Appends a new $facet operator to this aggregate pipeline. + * @param arg $facet operator contents + */ + facet(arg: any): this; + // If cursor option is on, could return an object /** Executes the aggregate pipeline on the currently bound Model. */ exec(callback?: (err: any, result: T) => void): Promise | any; /** Execute the aggregation with explain */ explain(callback?: (err: any, result: T) => void): Promise; - + /** * Appends a new custom $group operator to this aggregate pipeline. * @param arg $group operator contents diff --git a/types/mongoose/mongoose-tests.ts b/types/mongoose/mongoose-tests.ts index af8770dc28..9d9060bbc1 100644 --- a/types/mongoose/mongoose-tests.ts +++ b/types/mongoose/mongoose-tests.ts @@ -1227,6 +1227,7 @@ 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.facet({ fieldA: [{ a: 1 }], fieldB: [{ b: 1 }] }); aggregate.cursor({ batchSize: 1000 }).exec().each(cb); aggregate.exec().then(cb).catch(cb); aggregate.option({foo: 'bar'}).exec(); From a1ef1a70ce5a47ea49652f76bacf968a13cefd81 Mon Sep 17 00:00:00 2001 From: Alexandr Ni Date: Tue, 4 Sep 2018 09:23:47 -0400 Subject: [PATCH 2/2] Fixed arg type for facet function --- types/mongoose/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/mongoose/index.d.ts b/types/mongoose/index.d.ts index cd2da11312..1cd9d7c5b9 100644 --- a/types/mongoose/index.d.ts +++ b/types/mongoose/index.d.ts @@ -2340,7 +2340,7 @@ declare module "mongoose" { * Appends a new $facet operator to this aggregate pipeline. * @param arg $facet operator contents */ - facet(arg: any): this; + facet(arg: { [outputField: string]: object[] }): this; // If cursor option is on, could return an object /** Executes the aggregate pipeline on the currently bound Model. */ @@ -2348,7 +2348,7 @@ declare module "mongoose" { /** Execute the aggregation with explain */ explain(callback?: (err: any, result: T) => void): Promise; - + /** * Appends a new custom $group operator to this aggregate pipeline. * @param arg $group operator contents