我正在尝试通过我的 node.js 服务器将 2000 x 2000 2d 数组插入到我的 mongoDB 实例中。
现在我这样做的方式是:
for (i=0; i<2000; i++){
//i = height of the tile map
for(x=0; x<2000; x++){
//x is the width of the tile map
driver.mongo.insert('worldTiles', {loc: [x,i], elevation: obj.server.theArray[i][x]}, function (err,results){
if(!err){
}else{
console.log('Ran into an error inserting into worldTiles on Mongo');
}
})
}
console.log(i);
}
现在,我面临的问题是,在第 576 行左右,我的 node.js 实例显着减慢(每 40 秒左右处理一行),然后内存不足。我不明白这是如何/为什么会发生的。
我是否正确地解决了这个问题?关于如何在不费力的情况下将这个二维数组放入我的数据库的任何想法?
谢谢大家的帮助。