i want to mongodb query this sql query's:
select x,y,message,foo from messege where x=1 and y=1 group by x,y order by _id DESC
but with :
MongoCollection::group
can anyone help me?
i want to mongodb query this sql query's:
select x,y,message,foo from messege where x=1 and y=1 group by x,y order by _id DESC
but with :
MongoCollection::group
can anyone help me?
For this
select a,b,sum(c) csum from coll where active=1 group by a,b
The respective is
db.coll.group(
{key: { a:true, b:true },
cond: { active:1 },
reduce: function(obj,prev) { prev.csum += obj.c; },
initial: { csum: 0 }
});
You cannot sort the results you get from group, you can use sort for find like this for desc -1 , 1 for asc : .sort({"_id":-1}) desc
check this http://www.mongodb.org/display/DOCS/Aggregation#Aggregation-Group