Skip to content

Instantly share code, notes, and snippets.

@guidouil
Created November 16, 2017 16:32
Show Gist options
  • Save guidouil/147774bc36d0d62e1376eedaa1b54ff0 to your computer and use it in GitHub Desktop.
Save guidouil/147774bc36d0d62e1376eedaa1b54ff0 to your computer and use it in GitHub Desktop.
return Surveys.aggregate(
{ $match: query },
{ $group: {
_id: dateGroup,
participants: { $sum: '$ratersCount' },
rating: { $avg: '$averageRating' },
surveys: { $push: '$_id' },
selectedTags: { $push: '$tags' },
peoples: { $addToSet: '$fullname' },
} },
{ $project: {
_id: null,
selectedTags: {
$reduce: {
input: "$selectedTags",
initialValue: [],
in: { $setUnion: ["$$value", "$$this"] }
}
},
} }
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment