Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mongodb-aggregate-builder

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongodb-aggregate-builder

Builder for generate aggregation query for MongoDB

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

MongoDB Aggregate Builder

This library developed on Typescript.

The MongoDB Aggregate Builder is a powerful tool designed to simplify the process of creating and managing aggregate rules in an object-oriented programming paradigm. An aggregate rule is a rule that operates on a collection of objects or entities rather than individual ones, allowing for efficient and cohesive processing of data.

This library provides a comprehensive set of features and abstractions to define and manipulate aggregate rules. It encourages encapsulation, modularization, and reusability, promoting clean and maintainable code. With this library, developers can easily create, compose, and apply aggregate rules in their applications without the need for extensive boilerplate code.

In summary, the MongoDB Aggregate Builder empowers developers to design, manage, and apply aggregate rules in an object-oriented programming style. It promotes code reuse, extensibility, and maintainability, making it an invaluable tool for applications that deal with complex rule-based operations on collections of objects or entities.

Install

Run next command

npm i mongodb-aggregate-builder

Custom rules

  • MergeAggregation
  • MergeAggregationWithCurrent

Implemented rules

Implemented expressions

  • toObjectId
  • toBool
  • toDate
  • toNumber
  • toString
  • toLong
  • toDouble
  • toDecimal
  • toInt
  • toLower
  • toUpper
  • first
  • last
  • firstN
  • lastN
  • floor
  • function - functionOperation or alias func
  • concatArrays

Custom helpers

Usage

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);

console.log(JSON.stringify(aggBuilder.build(), null, 2));

Result

[
  {
    "$match": {
      "$and": [
        {
          "name": "John"
        },
        {
          "age": {
            "$gt": 18
          }
        }
      ]
    }
  },
  {
    "$addFields": {
      "stringAge": {
        "$toString": "$age"
      }
    }
  }
]

License

MIT

Keywords

FAQs

Package last updated on 05 Aug 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc