Security News
New Proposed CISA Mandate Would Require Critical Infrastructure to Report Ransom Payments Within 24 Hours
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
mongo-simple-aggregation-builder
Advanced tools
A Node.js typescript implementation of mongodb aggregation query builder
Weekly downloads
Readme
A Node.js typescript implementation of mongodb aggregation query builder
Instead of creating huge static query objects, aggregation queries can be constructed in a flexible, imperative manner using this builder.
Mongo-simple-aggregation-builder comes with TypeScripdefinitions experience.
What's Included:
npm install mongo-simple-aggregation-builder --save
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', 'calculated_field');
const pipeline = new Builder()
.match(matchStage)
.project(projectStage)
.group(groupStage)
.build();
const response = await db.<collection>.aggregate(pipeline);
test('project Builder', () => {
const expected = {
field_name: 1,
calculated_field: '$another_field',
remove_field: 0,
};
const recieved = new ProjectBuilder()
.includeField('field_name')
.addField('calculated_field', '$another_field')
.excludeField('remove_field');
expect(recieved).toEqual(expected);
});
test('group Builder', () => {
const expected = {
_id: 'groupName',
aggregated_field: { $sum: '$aggregated_val' },
};
const recieved = new GroupBuilder('groupName').sum('aggregated_field', 'aggregated_val');
expect(recieved).toEqual(expected);
});
test('filter and return first from db array', () => {
const expected = {
mysql_db: {
$first: {
$filter: { input: '$db_list', as: 'db', cond: { $eq: ['$$db.name', 'mysql'] } },
},
},
};
const mysqlDbField = new Comparison(Operator.EQ, '$$db.name', 'mysql');
const filterSourcesArray = new Filter('$db_list', 'db', mysqlDbField);
const received = new ProjectBuilder().addField('mysql_db', filterSourcesArray.first());
expect(JSON.stringify(received)).toEqual(JSON.stringify(expected));
});
FAQs
A Node.js typescript implementation of mongodb aggregation query builder
The npm package mongo-simple-aggregation-builder receives a total of 2 weekly downloads. As such, mongo-simple-aggregation-builder popularity was classified as not popular.
We found that mongo-simple-aggregation-builder demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
Security News
Redis is no longer OSS, breaking its explicit commitment to remain under the BSD 3-Clause License forever. This has angered contributors who are now working to fork the software.
Product
Socket AI now enables 'AI detected potential malware' alerts by default, ensuring users benefit from AI-powered state-of-the-art malware detection without needing to opt-in.