
Research
/Security News
DuckDB npm Account Compromised in Continuing Supply Chain Attack
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
@sachin-chourasiya/mongoose-aggregation-builder
Advanced tools
A secure, chainable MongoDB aggregation builder for Mongoose with input validation and safe defaults.
A simple, secure, and chainable MongoDB aggregation pipeline builder for Mongoose.
It makes complex aggregation queries easier to write, readable, and safe from injection risks.
Writing raw MongoDB aggregation pipelines can be verbose and hard to maintain:
User.aggregate([
{ $match: { status: 'active' } },
{
$lookup: {
from: 'orders',
localField: '_id',
foreignField: 'userId',
as: 'orders',
},
},
{ $unwind: { path: '$orders', preserveNullAndEmptyArrays: true } },
{ $group: { _id: '$_id', totalOrders: { $sum: 1 } } },
{ $sort: { totalOrders: -1 } },
{ $limit: 10 },
]);
With @sachin-chourasiya/mongoose-aggregation-builder:
const pipeline = Agg()
.filter({ status: 'active' })
.join('orders', '_id', 'userId', 'orders')
.unwind('orders', true)
.countOrders()
.sortBy('totalOrders', 'desc')
.limit(10)
.build();
User.aggregate(pipeline);
npm install @sachin-chourasiya/mongoose-aggregation-builder
.d.ts
type definitions (coming soon)const Agg = require('@sachin-chourasiya/mongoose-aggregation-builder');
const pipeline = Agg()
.filter({ isActive: true })
.project({ name: 1, email: 1 })
.build();
User.aggregate(pipeline);
Generated Pipeline:
[{ $match: { isActive: true } }, { $project: { name: 1, email: 1 } }];
const pipeline = Agg()
.filter({ status: 'active' })
.join('orders', '_id', 'userId', 'orders')
.unwind('orders')
.build();
User.aggregate(pipeline);
Generated Pipeline:
[
{ $match: { status: 'active' } },
{
$lookup: {
from: 'orders',
localField: '_id',
foreignField: 'userId',
as: 'orders',
},
},
{ $unwind: '$orders' },
];
const pipeline = Agg()
.filter({ status: 'active' })
.groupBy('_id', { totalOrders: { $sum: 1 } })
.sortBy('totalOrders', 'desc')
.limit(5)
.build();
User.aggregate(pipeline);
$
operator injection in keys.filter(query)
Adds a $match
stage to filter documents.
.project(fields)
Adds a $project
stage.
.join(collection, localField, foreignField, as)
Adds a $lookup
stage to join another collection.
.unwind(path, preserveNull = false)
Adds a $unwind
stage.
.groupBy(id, accumulators)
Adds a $group
stage.
.countOrders()
Custom helper β counts number of joined documents.
.sortBy(field, order = "asc")
Adds a $sort
stage.
.limit(n)
Adds a $limit
stage.
.build()
Returns the final aggregation pipeline array.
MIT License Β© 2025
FAQs
A secure, chainable MongoDB aggregation builder for Mongoose with input validation and safe defaults.
The npm package @sachin-chourasiya/mongoose-aggregation-builder receives a total of 3 weekly downloads. As such, @sachin-chourasiya/mongoose-aggregation-builder popularity was classified as not popular.
We found that @sachin-chourasiya/mongoose-aggregation-builder demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.
Product
Socketβs new Pull Request Stories give security teams clear visibility into dependency risks and outcomes across scanned pull requests.