我想MongoDB中查询这个SQL查询的:蒙戈DB组顺序
select x,y,message,foo from messege where x=1 and y=1 group by x,y order by _id DESC
但:
MongoCollection ::组
谁能帮助我?
我想MongoDB中查询这个SQL查询的:蒙戈DB组顺序
select x,y,message,foo from messege where x=1 and y=1 group by x,y order by _id DESC
但:
MongoCollection ::组
谁能帮助我?
对于这个
select a,b,sum(c) csum from coll where active=1 group by a,b
相应的是
db.coll.group(
{key: { a:true, b:true },
cond: { active:1 },
reduce: function(obj,prev) { prev.csum += obj.c; },
initial: { csum: 0 }
});
你不能从小组得到的结果进行排序,可以排序用于找到这样的递减-1,1 ASC:的.sort({ “_编码”: - 1})递减
检查此http://www.mongodb.org/display/DOCS/Aggregation#Aggregation-Group
http://stackoverflow.com/questions/ 3214406/how to to group with by mongodb?rq = 1 – int
我对查询中的“order by”部分感到困惑 - 由于您正在按单个值进行分组,因此您只会得到单个结果(x和y都1) - 你确定这是你真正想要的SQL吗?这里没有聚合。 –
@AsyaKamsky 是的,我在mysql上测试它 – Musher