> Let's ignore the [mongo] query format itself, as it's obviously meant to be generated by a tool rather than typed by a human being. Here's the same query in SQL, with the result this time
Priceless.
Priceless.
db.games.aggregate([
{ $match : { date : { $gt : ISODate("1999-08-01T00:00:00Z"), $lt : ISODate("2000-08-01T00:00:00Z") }}},
{ $unwind : '$teams' },
{ $match : { 'teams.won' : 1 }},
{ $group : { _id : '$teams.name', wins : { $sum : 1 }}},
{ $sort : { wins : -1 }},
{ $limit : 5 }
]);