db-aggregation-pipeline-builder
v1.0.0
Published
A simple aggregation pipeline builder for selected databases
Downloads
58
Readme
DB Aggregation Pipeline Builder
A simple aggregation pipeline builder for selected databases.
Description
This project provides a utility to build and validate MongoDB aggregation pipelines. It includes various stages and their configurations to ensure the pipeline is correctly structured before execution.
Installation
To install the package, run:
npm install db-aggregation-pipeline-builder
Usage
Importing the Module
import { validatePipeline, runPipeline, validateStageConfig, getViewOnlyStages } from 'db-aggregation-pipeline-builder';
example
import mongoose from 'mongoose';
import { validatePipeline, runPipeline } from 'db-aggregation-pipeline-builder';
const pipeline = [
{ $match: { status: 'active' } },
{ $group: { _id: '$category', total: { $sum: '$amount' } } },
];
const model = mongoose.model('YourModel', new mongoose.Schema({}));
async function executePipeline() {
try {
const result = await runPipeline(model, pipeline);
console.log(result);
} catch (error) {
console.error('Pipeline execution failed:', error);
}
}
executePipeline();
Development
Scripts
npm run build
- Compiles the TypeScript code to JavaScript.npm run build:watch
- Compile the TypeScript code to JavaScript in watch mode.npm run test
- Run the tests using Jest..npm run lint
- Run ESLint to check for code quality issues.npm run dev
- RRun the build and test scripts concurrently in watch mode.
Publishing
To publish the package to npm, follow these steps:
npm run build
- After testing and linting, build package.npm run prepare
- Prepare for publishing.npm publish
- Publiah.