collection.aggregate

Mongo documentation

Calculates aggregate values for the data in a collection.

Arguments

  1. pipeline (Array): A sequence of data aggregation operations or stages.

  2. [options] (object)

  3. [callback] (function)

Returns

A promise

Example

users.aggregate([
  { $project : {
    author : 1,
    tags : 1
  }},
  { $unwind : "$tags" },
  { $group : {
    _id : {tags : "$tags"},
    authors : { $addToSet : "$author" }
  }}
]).then((res) => {})

results matching ""

    No results matching ""