This package will make you write aggregate in a more terse way much like lodash utilities
yarn add @entria/mongo-aggregate-lodash
- 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'),
}
}