Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/438.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript forEach不';t迭代mongodb中的所有集合_Javascript_Mongodb_Robo3t - Fatal编程技术网

Javascript forEach不';t迭代mongodb中的所有集合

Javascript forEach不';t迭代mongodb中的所有集合,javascript,mongodb,robo3t,Javascript,Mongodb,Robo3t,我需要比较mongo db中的两个对象集合。 我的shell脚本如下所示: //Both arrays have 367 pretty big objects. var list1 = db.collection1.find({..condition..}).toArray(); var list2 = db.collection2.find({..condition..}).toArray(); function compare(left, right){ var l = left.

我需要比较mongo db中的两个对象集合。 我的shell脚本如下所示:

//Both arrays have 367 pretty big objects.
var list1 = db.collection1.find({..condition..}).toArray(); 
var list2 = db.collection2.find({..condition..}).toArray();

function compare(left, right){
   var l = left.data.NP;
   var r = right.data.NP;
   if(JSON.stringify(l) === JSON.stringify(r)){
      return 'Equal';
   } else {
      return 'Not equal';
   }
}

list1.forEach(function(item, index){
   print(index, compare(item,list2[index]));
})
我在机器人世界里执行这个脚本。 但我有个问题。结果只打印了367中的8项。Robomongo没有显示任何错误消息。 当我使用

print(item);
在foreach内部,所有的工作都很好,所有367件物品都被打印出来了。我还尝试使用deepdiff库进行对象比较,但得到了相同的结果——367中只有12项被打印出来

我认为问题在于内存消耗,但我不知道如何处理它,以及为什么Robomongo不打印任何错误

我尝试只迭代游标,但没有帮助

为什么foreach不能迭代所有项,以及如何修复它

[更新1] 经过一段时间的调查后,我提到,如果我在Robomongo中刚打开的选项卡中运行脚本,它将打印102个元素,但当我在同一选项卡中再次运行脚本时,它只打印12个元素

[更新2]
我尝试使用本机mongo shell mongo.exe运行脚本,从367个元素中打印了100个元素,没有出现错误

这可能与超时有关。Robomongo在配置文件中有15秒的默认超时时间,可以更改。这可能有助于:

[Update-1]
从版本Robo3T-1.1(以前的Robomongo)开始,shell超时在UI上是可配置的,并且有一个修复程序可以防止此问题发生。看见 . 因此,对于旧版本,无需更改配置文件,如下所述

Windows
  0.9.x
  C:\Users\<user>\.config\robomongo\0.9\robomongo.json
  0.8.x
  C:\Users\<user>\.config\robomongo\robomongo.json   
MAC
    0.9.x
    /Users/<user>/.config/robomongo/0.9/robomongo.json
    0.8.x
   /Users/<user>/.config/robomongo/robomongo.json     
Linux
    0.9.x
    /home/<user>/.config/robomongo/0.9/robomongo.json
    0.8.x
    /home/<user>/.config/robomongo/robomongo.json
早于1.1版本的变通解决方案:

确保关闭Robomongo。打开robomongo.json配置文件

[更新]:为更新版本添加指向的链接

Windows
  0.9.x
  C:\Users\<user>\.config\robomongo\0.9\robomongo.json
  0.8.x
  C:\Users\<user>\.config\robomongo\robomongo.json   
MAC
    0.9.x
    /Users/<user>/.config/robomongo/0.9/robomongo.json
    0.8.x
   /Users/<user>/.config/robomongo/robomongo.json     
Linux
    0.9.x
    /home/<user>/.config/robomongo/0.9/robomongo.json
    0.8.x
    /home/<user>/.config/robomongo/robomongo.json
Windows
0.9.x
C:\Users\\.config\robomongo\0.9\robomongo.json
0.8.x
C:\Users\\.config\robomongo\robomongo.json
雨衣
0.9.x
/Users//.config/robomongo/0.9/robomongo.json
0.8.x
/Users//.config/robomongo/robomongo.json
Linux
0.9.x
/home/.config/robomongo/0.9/robomongo.json
0.8.x
/home/.config/robomongo/robomongo.json
  • 将“shellTimeoutSec”属性值更改为更高的秒数。(即“shellTimeoutSec”:60)
  • 保存配置文件并重新启动Robomongo应用程序
  • 运行必要的脚本。如果脚本未完全执行,请尝试增加shellTimeoutSec值
  • 参考: