1.0.1 • Published 3 years ago

node-aggregation-tools v1.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

node-aggregation-tools

Technical documentation

npm package

npm i node-aggregation-tools

Usage:

- with require

const aggregator = require("node-aggregation-tools");

- with import

import { Aggregator } from 'node-aggregation-tools';

Example with Student model:

const Student = new mongoose.model("Student", {
    name: String,
    city: String,
    subject: [String]
});

Example of pipline:

const getStudentList = new Aggregator(Student)
    .match({ city: "Rajkot" })
    .project({ _id: false, name: true, subject: true })
    .unwind({ path: "$subject" })
    .limit(2)
    .build();
    
const aggregateStudent = await getStudentList.print().exec();

Try the lib on NPM RunKit with the require method

MONGODB STAGES: