分配失败 - JavaScript堆内存不足 - 节点js

时间:2017-10-04 07:14:21

标签: javascript node.js mongodb async.js

我们有一个集合,可以在一个集合中存储100 000个文档。我必须获取所有数据然后更新它(通过添加一个键)。

这是代码

 checkinLib.getCheckinModel().find({},function(error, result){
        if(error){
            console.log('error', error);
        }
        else{
            console.log("length", result.length)
            async.forEachSeries(result, function(data, cb){
                console.log("data1", data)
                if(data.checkinData.time){
                    var dt = data.checkinData.time.toString();
                    var month = new Date(dt).getMonth();
                    var ss = parseInt(month);
                    var format = new Date(dt).getFullYear() + '-' + (ss+1) + '-' + new Date(dt).getDate();
                    checkinLib.getCheckinModel().update({'_id': data._id}, {'$set':{'checkinData.dateFormat': format}}, (err, update)=>{
                        if(err){
                            console.log('err', err);
                        }
                        else{
                            cb()
                        }
                    })
                }
            },function(error, result){
                console.log("finally error", error);
                console.log("finally data", result);
            })
        }
    })

获取需要太多时间。当我在终端上检查控制台然后它返回

  <--- Last few GCs --->

  [3921:0x2c54c40]   166610 ms: Mark-sweep 1403.1 (1463.4) -> 1403.1 
  (1463.4) MB, 2717.4 / 0.0 ms  allocation failure GC in old space 
   requested
  [3921:0x2c54c40]   169350 ms: Mark-sweep 1403.1 (1463.4) -> 1403.0 
  (1438.4) MB, 2739.6 / 0.0 ms  last resort 
   [3921:0x2c54c40]   172066 ms: Mark-sweep 1403.0 (1438.4) -> 1403.0 
 (1437.9) MB, 2715.7 / 0.0 ms  last resort 


<--- JS stacktrace --->

   ==== JS stack trace =========================================

  Security context: 0xd093db9cef1 <JSObject>
   1: pre [/home/rahul/Documents/bluedolphinapi/node_modules/hooks-
  fixed/hooks.js:~116] [pc=0x19b16ba1a964](this=0x3e51244ca7e9 <model 
 map = 0x39723645c251>,name=0x15ea23ee34d1 <String[16]: 
 $__original_save>,isAsync=0xd093db822f1 <false>,fn=0x113b342daf9 
<JSFunction fn (sfi = 0xd83c50733d1)>,errorCb=0xd093db82241 
 <undefined>)
2: arguments adaptor frame: 3->4
4: /* anonymous */ [/home/rah...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap 
out of memory
1: node::Abort() [/usr/local/bin/node]
2: 0x13740dc [/usr/local/bin/node]
3: v8::Utils::ReportOOMFailure(char const*, bool) [ 
/usr/local/bin/node]
4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) 
[/usr/local/bin/node]
5: v8::internal::Factory::NewFillerObject(int, bool, 
v8::internal::AllocationSpace) [/usr/local/bin/node]
6: v8::internal::Runtime_AllocateInTargetSpace(int, 
v8::internal::Object**, v8::internal::Isolate*) [/usr/local/bin/node]
7: 0x19b16b8840dd

我已经运行了这个命令

node --max-old-space-size=4096 fileName.js

没有任何反应,我的系统已挂起,没有任何数据更新。

节点版本是v8.4.0

Npm版本是5.3.0

我有很多搜索并尝试但仍然无法正常工作,是否有任何方法或查询可以更新所有文档?

0 个答案:

没有答案