我想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