mongo-simple-aggregation-builder
Advanced tools
Comparing version 1.0.2 to 1.0.3
import { Expression } from 'src/objects/expression'; | ||
export declare class MatchBuilder { | ||
expression(expr: Expression): this & Expression; | ||
match(fieldName: any, fieldValue: any): this; | ||
} |
@@ -8,4 +8,8 @@ "use strict"; | ||
} | ||
match(fieldName, fieldValue) { | ||
this[fieldName] = fieldValue; | ||
return this; | ||
} | ||
} | ||
exports.MatchBuilder = MatchBuilder; | ||
//# sourceMappingURL=match.js.map |
@@ -44,2 +44,9 @@ "use strict"; | ||
}); | ||
test('match', () => { | ||
const expectResult = { | ||
field_name: 'value', | ||
}; | ||
const actualResult = new match_1.MatchBuilder().match('field_name', 'value'); | ||
expect(expectResult).toEqual(actualResult); | ||
}); | ||
test('test structure', () => { | ||
@@ -46,0 +53,0 @@ const query = [ |
{ | ||
"name": "mongo-simple-aggregation-builder", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -29,6 +29,20 @@ # mongo-simple-aggregation-builder | ||
## Usage | ||
```ts | ||
import { Builder, FacetBuilder, GroupBuilder, MatchBuilder, ProjectBuilder } from 'mongo-simple-aggregation-builder' | ||
``` | ||
const matchStage = new MatchBuilder().match('field_name', 'value'); | ||
const projectStage = new ProjectBuilder() | ||
.includeField('field_name') | ||
.addField('calculated_field', '$another_field'); | ||
const groupStage = new GroupBuilder('id') | ||
.count('total') | ||
.sum('aggregated_field', 'aggregated_val'); | ||
const pipeline = new Builder() | ||
.match(matchStage) | ||
.project(projectStage) | ||
.group(groupStage) | ||
.build(); | ||
``` | ||
@@ -35,0 +49,0 @@ |
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
43101
382
65