I have a query which find the goals average of football teams, group by teams.
db.matchs.aggregate([{$group: {_id:"$equipes_domicile", pop: {$avg:"$score_equipe_domicile"} } }])
but i want only select them with an average greater than 4.
CodePudding user response:
You can do:
db.matchs.aggregate([
{$group: {_id:"$equipes_domicile", pop: {$avg:"$score_equipe_domicile"} } },
{$match: {pop: {$gt: 4}}}
])
The $match
will choose only documents with pop
greater than 4.