2011-09-20 117 views
0

我想執行一個地圖減少直接到Mongo獲得頂部標籤,但我得到這個錯誤,我不知道它是什麼意思,它與它做什麼。任何指導?地圖減少投擲錯誤:MongoDB

> reduce= function(previous, current) { 
... var count = 0; 
... 
...  for (index in current) { 
...   count += current[index]; 
...  } 
... 
...  return count; 
... } 
function (previous, current) { 
    var count = 0; 
    for (index in current) { 
     count += current[index]; 
    } 
    return count; 
} 
> reduce 
function (previous, current) { 
    var count = 0; 
    for (index in current) { 
     count += current[index]; 
    } 
    return count; 
} 
> map = function() { 
... if (!this.stores) { 
... return; 
...  } 
... for (index in this.stores) { 
... emit(this.stores[index], 1); 
... } 
... } 
function() { 
    if (!this.stores) { 
     return; 
    } 
    for (index in this.stores) { 
     emit(this.stores[index], 1); 
    } 
} 
> map 
function() { 
    if (!this.stores) { 
     return; 
    } 
    for (index in this.stores) { 
     emit(this.stores[index], 1); 
    } 
} 
> result = db.runCommand({ 
... "mapreduce" : "users", 
... "map" : map, 
... "reduce" : reduce, 
... "out" : "tags"}) 
{ 
    "assertion" : "_id cannot be an array", 
    "assertionCode" : 10099, 
    "errmsg" : "db assertion failure", 
    "ok" : 0 
} 

回答

1
"assertion" : "_id cannot be an array" 

可能意味着你的this.stores [索引]數組引起MapReduce的結果已經_id爲您的地圖鍵