あなたはsum(GDP)
によってcountry
とでフィルタしたい場合は、グループ化する前に、一致段階を追加します。たとえば:
db.world_gdp.aggregate([
// focus on BR, CN and UK countries ... the subsequent stages in the
// pipeline will only get docs for these countries
{ $match: { country: { $in: ['BR', 'CN', 'UK'] } } },
// group by country and sum GDP
{ $group: { _id: "$country", gdp: { $sum: "$gdp"} } },
// restrict to those countries having sum(GDP) >= 2500
{ $match: { gdp: { $gte: 2500 } } },
// sort by sum(GDP)
{ $sort: { gdp: -1 } }
])
それとも、あなたはsum(GDP)
によって代わりフィルタリングのcountry
によるフィルタリングに興味があるならば、この試してみてください。
db.world_gdp.aggregate([
// focus on BR, CN and UK countries ... the subsequent stages in the
// pipeline will only get docs for these countries
{ $match: { country: { $in: ['BR', 'CN', 'UK'] } } },
// group by country and sum GDP
{ $group: { _id: "$country", gdp: { $sum: "$gdp"} } },
// sort by sum(GDP)
{ $sort: { gdp: -1 } }
])
は、あなたがしてください、実行されているクエリを投稿することができますか? – robjwilkins