我正在尝试通过mongo shell运行group命令
db.contract.group({
key:{id: 1},
initial: {v: []},
reduce: function(obj, prev){
prev.v.push(obj.name)
}
});
并在客户端上看到以下错误
Thu Nov 17 12:12:49 uncaught exception: group command failed: {
"errmsg" : "exception: JS_NewObject failed: toJSObject2",
"code" : 13072,
"ok" : 0
}
和mongod日志说明如下
Thu Nov 17 12:12:17 [initandlisten] connection accepted from 127.0.0.1:58509 #1
Thu Nov 17 12:12:49 [conn1] JS Error: out of memory
Thu Nov 17 12:12:49 [conn1] Assertion: 13072:JS_NewObject failed: toJSObject2
0x10008de9b 0x1001565bd 0x100156c9e 0x10037011e 0x10037204c 0x10034c4d6 0x10034d877 0x100180cc4 0x100184649 0x1002b9e89 0x1002c3f18 0x100433888 0x100446d74 0x7fff86e00fd6 0x7fff86e00e89
0 mongod 0x000000010008de9b _ZN5mongo11msgassertedEiPKc + 315
1 mongod 0x00000001001565bd _ZN5mongo9Convertor10toJSObjectEPKNS_7BSONObjEb + 1229
2 mongod 0x0000000100156c9e _ZN5mongo7SMScope9setObjectEPKcRKNS_7BSONObjEb + 78
3 mongod 0x000000010037011e _ZN5mongo12GroupCommand5groupESsRKSsRKNS_7BSONObjES3_SsSsPKcS3_SsRSsRNS_14BSONObjBuilderE + 2110
4 mongod 0x000000010037204c _ZN5mongo12GroupCommand3runERKSsRNS_7BSONObjERSsRNS_14BSONObjBuilderEb + 3676
5 mongod 0x000000010034c4d6 _ZN5mongo11execCommandEPNS_7CommandERNS_6ClientEiPKcRNS_7BSONObjERNS_14BSONObjBuilderEb + 1350
6 mongod 0x000000010034d877 _ZN5mongo12_runCommandsEPKcRNS_7BSONObjERNS_10BufBuilderERNS_14BSONObjBuilderEbi + 2151
7 mongod 0x0000000100180cc4 _ZN5mongo11runCommandsEPKcRNS_7BSONObjERNS_5CurOpERNS_10BufBuilderERNS_14BSONObjBuilderEbi + 52
8 mongod 0x0000000100184649 _ZN5mongo8runQueryERNS_7MessageERNS_12QueryMessageERNS_5CurOpES1_ + 10585
9 mongod 0x00000001002b9e89 _ZN5mongo13receivedQueryERNS_6ClientERNS_10DbResponseERNS_7MessageE + 569
10 mongod 0x00000001002c3f18 _ZN5mongo16assembleResponseERNS_7MessageERNS_10DbResponseERKNS_8SockAddrE + 1528
11 mongod 0x0000000100433888 _ZN5mongo10connThreadEPNS_13MessagingPortE + 616
12 mongod 0x0000000100446d74 thread_proxy + 132
13 libSystem.B.dylib 0x00007fff86e00fd6 _pthread_start + 331
14 libSystem.B.dylib 0x00007fff86e00e89 thread_start + 13
Thu Nov 17 12:12:49 [conn1] query staging.$cmd ntoreturn:1 command: { group: { key: { asset_id: 1.0 }, initial: { v: {} }, ns: "contract", $reduce: function (obj, prev) {
prev.v.push(obj.name);
} } } reslen:119 21013ms
我尝试检查虚拟内存是否无限制且是
bash-3.2$ ulimit -a | egrep virtual\|open
open files (-n) 256
virtual memory (kbytes, -v) unlimited
所以我不确定如何解决这个问题
谢谢
答案 0 :(得分:2)
Mongo正在内存中进行分组,因此如果你有一个包含许多不同id值的大型数据库,那么事情可能会变得太大。
此外,您正在为一个数组中的给定ID堆积所有名称。 Mongo中的最大文档大小也有限制,如果您有给定ID的许多文档,则可能是内存不足错误的原因。
我想解决方法是使用map / reduce。