Documentation is sparse on the aggregation function. I don't know what the array parameters are and keep getting errors with everything I try. I can sucessfully do aggregation from the mongo shell. I just don't know how to translate that into the Phalcon function.
$articles = Article::aggregate(array(...));
Articles looks like:
{
"title" : "App Envy",
"description" : "My Top 10 Android Apps",
"author" : "Joe",
"date" : ISODate("2013-01-24T08:00:00Z"),
"last_update" : null,
"active" : "",
"category" : "technology",
"_id" : ObjectId("51021cf9e73c84170d000000"),
"text" : "Lorem Ipsum ...",
"last_updated" : ISODate("2013-03-26T04:18:26.622Z")
}
This is my aggregation query in the mongo shell which works:
var results = new Array();
db.articles.aggregate(
{ $project : {
category: 1,
} },
{ $group : {
_id : {category: "$category"},
id : {$max : "$_id"},
}
}
).result.forEach(function(o) {
results.push(db.articles.findOne(o.id));
});
results.forEach(printjson);