Skip to content

Latest commit

 

History

History
39 lines (32 loc) · 680 Bytes

README.md

File metadata and controls

39 lines (32 loc) · 680 Bytes

Mongo Aggregate Lodash

This package will make you write aggregate in a more terse way much like lodash utilities

How to install

yarn add @entria/mongo-aggregate-lodash

Examples

  • Without using mongo-aggregate-lodash
{
  $group: {
     averageDividend: {
        $sum: {
          $multiply: ['$score', '$field.weight'],
        }
    },
    averageDivisor: {
       $sum: '$field.weight'
    },
  }
}
  • Using mongo-aggregate-lodash
import { sum, multiply } from '@entria/mongo-aggregate-lodash';

{
  $group: {
     averageDividend: sum(multiply('$score', '$field.weight')),
      averageDivisor: sum('$field.weight'),
  }
}