2011-09-20 55 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为您的地图键