bridge-mongo
Advanced tools
Comparing version 0.0.17 to 0.0.18
@@ -11,2 +11,3 @@ import { Model as MongoModel, PipelineStage } from 'mongoose'; | ||
lookup: AggI<ModelI, AllDBI>['lookup']; | ||
lookupCount: AggI<ModelI, AllDBI>['lookupCount']; | ||
group: AggI<ModelI, AllDBI>['group']; | ||
@@ -13,0 +14,0 @@ unset: AggI<ModelI, AllDBI>['unset']; |
@@ -25,3 +25,2 @@ "use strict"; | ||
}); | ||
console.log(realProj); | ||
return new Aggregate(this.mongoModel, [...this.pipe, { $addFields: realProj }]); | ||
@@ -44,2 +43,16 @@ }; | ||
}; | ||
lookupCount = (lookupParam, aggregateMethod) => { | ||
let lookup = { | ||
from: (0, pluralize_1.default)(lookupParam.from), | ||
as: lookupParam.as, | ||
}; | ||
if (lookupParam.let) | ||
lookup.let = lookupParam.let; | ||
let paramLookupAggregate = {}; | ||
Object.keys(lookupParam.let || {}).forEach((key) => { | ||
paramLookupAggregate[key] = `$$${key}`; | ||
}); | ||
lookup.pipeline = [...aggregateMethod(new Aggregate(), paramLookupAggregate).pipe, { $count: 'Total' }]; | ||
return new Aggregate(this.mongoModel, [...this.pipe, { $lookup: lookup }]); | ||
}; | ||
group = (group) => new Aggregate(this.mongoModel, [...this.pipe, { $group: group }]); | ||
@@ -46,0 +59,0 @@ unset = (unset) => new Aggregate(this.mongoModel, [...this.pipe, { $unset: unset }]); |
@@ -79,2 +79,11 @@ import { PipelineStage } from 'mongoose'; | ||
}, AllDBI>; | ||
lookupCount: <Let extends Record<string, `$${keyof ModelI extends string ? keyof ModelI : never}`>, From extends keyof AllDBI & string, NewModel, AS extends string = From>(p1: { | ||
from: From; | ||
as: AS; | ||
let?: Let; | ||
}, p2: (p1: AggI<AllDBI[From], AllDBI>, p2: { | ||
[key in keyof Let]: `$$${key extends string ? key : never}`; | ||
}) => AggI<NewModel, AllDBI>) => AggI<ModelI & { | ||
[P in AS]: number; | ||
}, AllDBI>; | ||
unwind: <KeyOfArrayToUnwind extends keyof ModelI & KeysWithValsOfType<ModelI, Array<any>>, PreserveNull extends boolean = false>(p: { | ||
@@ -81,0 +90,0 @@ path: `$${KeyOfArrayToUnwind extends string ? KeyOfArrayToUnwind : never}`; |
{ | ||
"name": "bridge-mongo", | ||
"version": "0.0.17", | ||
"version": "0.0.18", | ||
"description": "A mongodb ORM on top of mongoose that match perfectly with the bridgets framework", | ||
@@ -5,0 +5,0 @@ "main": "dist/Lib/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
79471
996