0
的電流和我們有文件的MongoDB:田
{a: 1}
{a: 5}
{a: 3}
如何aggrerage與鈣電流和數據?
{a: 1, cs: 1}
{a: 5, cs: 6}
{a: 3, cs: 9}
的電流和我們有文件的MongoDB:田
{a: 1}
{a: 5}
{a: 3}
如何aggrerage與鈣電流和數據?
{a: 1, cs: 1}
{a: 5, cs: 6}
{a: 3, cs: 9}
你只能做這樣的事情在目前的MongoDB中的MapReduce與。究其原因是目前是只地方可以保存「全局」變量,那就是基本上你需要什麼了「運行總計」:
db.collection.mapReduce(
function(){
totals += this.a;
emit(this._id, {"a": this.a, "cs": totals});
},
function() {}, // nothing to reduce here
{
"out": { "inline": 1 },
"scope": { "totals": 0 }
}
);
所以有「這裏沒有實際的分組「,但是如果你願意,你可以這樣做。重點是,這保持每個記錄的「運行總數」,這是你似乎要求的。
"mapReduce"命令有一個稱爲「範圍」的方面,用於實現可用於此類任務的「全局」變量。
'db.c.aggregate({_ id:'$ a',cs:{$ sum:1}})'除非計數來自其他地方 – Sammaye 2014-10-06 09:52:30