collection.aggregate
Calculates aggregate values for the data in a collection.
Arguments
pipeline(Array): A sequence of data aggregation operations or stages.[
options] (object)[
callback] (function)
Returns
A promise
Example
users.aggregate([
{ $project : {
author : 1,
tags : 1
}},
{ $unwind : "$tags" },
{ $group : {
_id : {tags : "$tags"},
authors : { $addToSet : "$author" }
}}
]).then((res) => {})