Registry / database / mongodb-aggregate-builder

mongodb-aggregate-builder

JSON →
library1.0.2jsnpmunverified

Version 1.0.2. A TypeScript library for building MongoDB aggregation pipelines using a fluent builder pattern. Supports all major aggregation stages (Match, Group, Lookup, Bucket, etc.), expressions (toString, toDate, first, last, etc.), and custom helpers. Provides an object-oriented API with full type safety and auto-completion, reducing boilerplate and errors compared to raw MongoDB pipeline objects. Actively maintained with frequent releases. Differentiator: strongly typed builder ensures pipeline correctness at compile time.

npm install mongodb-aggregate-builder
INSTALL
IMPORT
SIG · MONGODB-AGGREGATE-
M
mongodb-aggregate-builder
databasejavascriptv1.0.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

AggregateBuilder
import { AggregateBuilder } from 'mongodb-aggregate-builder'
const AggregateBuilder = require('mongodb-aggregate-builder')
Default export not available; use named import only.
Match, Group, Sort
import { Match, Group, Sort } from 'mongodb-aggregate-builder'
import { Match } from 'mongodb-aggregate-builder/Match'
All stages are exported from the main package index; no need for subpaths.
andExpr, toString
import { andExpr, toString } from 'mongodb-aggregate-builder'
import { andExpr } from 'mongodb-aggregate-builder/expressions'
Expressions are exported from the root, not a separate module.

Shows how to create a MongoDB aggregation pipeline with match, addFields, sort, skip, and limit using the fluent builder.

import { AggregateBuilder, andExpr, SortDirection, toString } from 'mongodb-aggregate-builder'; const aggBuilder = new AggregateBuilder(); aggBuilder .match(andExpr([{ name: 'John' }, { age: { $gt: 18 } }])) .addFields(toString('age', 'stringAge')) .sort({ age: SortDirection.ASC_TEXT }) .skip(10) .limit(5); const pipeline = aggBuilder.build(); console.log(JSON.stringify(pipeline, null, 2));
Debug
Known issues
gotchaOrder of pipeline stages matters: build() outputs stages in the order they were chained.
fix
Ensure match before group, etc.
affects: >=1.0.0
gotchaExpressions like toString must be used with addFields or project, not directly as stage objects.
fix
Use aggBuilder.addFields(toString('field', 'alias')) instead of passing toString to match.
affects: >=1.0.0
gotchaSortDirection.ASC_TEXT is a custom constant; MongoDB's sort direction for strings requires 1 or -1.
fix
Use SortDirection.ASC or SortDirection.DESC for numeric sorts; ASC_TEXT may not work as expected.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: aggregateBuilder.build is not a function
Using a lowercase instance name but calling build on something else.
fix
Ensure you use the correct variable: const builder = new AggregateBuilder(); builder.build();
Cannot find module 'mongodb-aggregate-builder'
Package not installed.
fix
Run: npm install mongodb-aggregate-builder
Property 'build' does not exist on type 'AggregateBuilder'
Using an older version that may not export build method properly.
fix
Update to latest version: npm install mongodb-aggregate-builder@latest
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
mongodb-aggregate-builder — npm install mongodb-aggregate-builder · libregistry