Skip to content

Instantly share code, notes, and snippets.

@mrlynn
Created July 18, 2024 17:57
Show Gist options
  • Save mrlynn/505b2f9c92a9d8ea8a71eba1019bbaef to your computer and use it in GitHub Desktop.
Save mrlynn/505b2f9c92a9d8ea8a71eba1019bbaef to your computer and use it in GitHub Desktop.
Example MongoDB Aggregation
db.reviews.aggregate([
{
$group: {
_id: "$bookId",
averageRating: {
$avg: "$rating"
}
}
},
{
$match: {
averageRating: 5
}
}
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment