On Fri, Jul 11, 2014, at 10:17 PM, Will Berkeley wrote:
> Hi. Use the aggregation framework
> <
http://docs.mongodb.org/manual/core/aggregation-introduction/>:
>
> db.states.aggregate([
> { "$unwind": "$cities" },
> { "$match": { "cities.population": { "$gte": 500000 } } },
> { "$group": { "_id": "$name", "cities": { "$push": "$cities" },
> "count":
> { "$inc" : 1 } } }
> { "$match": { "count" : { "gte" : 3 } } }
> ])
>
> This both finds all states with >= 3 cities of a half million people or
> more and returns those states with only cities of 500,000 or more people
> in
> the cities array.
>
Thanks! And by studying your example I much better understand the
aggregation framework ( I think you meant "$sum" instead of "$inc"
though.).