christkv/node-mongodb-native — Issue #508: How to use New Aggregation Framework?
Author: guileen
Created: 2012-02-14 06:56:00+00:00
State: open

http://www.mongodb.org/display/DOCS/Aggregation+Framework

If I want to run this command, how can I do it?

```
> db.runCommand({aggregate: "posts", pipeline: [
{
// extract the fields we'll need
$project: {
title : 1,
url : 1,
comments : 1
}
},
{
// explode "comments" array into separate documents
$unwind: "$comments"
},
{
// count up votes by author
$group : {
_id : "$comments.author",
popularity : {$sum : "$comments.votes"}
}
},
{
// sort by the new popular field
$sort: {
"popularity" : -1
}
}]})
```