title: MongoDB: JS Error: out of memory
body: <p>I am trying to run group command via mongo shell  </p>
  
  <pre><code>db.contract.group({
     key:{id: 1}, 
     initial: {v: []}, 
     reduce: function(obj, prev){ 
       prev.v.push(obj.name)
     } 
  });
  </code></pre>
  
  <p>and see the following error on client  </p>
  
  <pre><code>Thu Nov 17 12:12:49 uncaught exception: group command failed: {
      "errmsg" : "exception: JS_NewObject failed: toJSObject2",
      "code" : 13072,
      "ok" : 0
  }
  </code></pre>
  
  <p>and mongod logs says the following  </p>
  
  <pre><code>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
  </code></pre>
  
  <p>I tried checking if the virtual memory is unlimited and it is  </p>
  
  <pre><code>bash-3.2$ ulimit -a | egrep virtual\|open
  open files                      (-n) 256
  virtual memory          (kbytes, -v) unlimited
  </code></pre>
  
  <p>so I am not sure how to fix this problem  </p>
  
  <p>Thank you</p>