我正在对光标的每个元素执行一个进程,我的集合有大约 600 万个文档,整个过程最多需要 10 个小时,因为我必须一次处理一个配置文件,而且对于每一个。
\n\n var cursor = dbMain.collection("profiles").find({});\n\n var getNext = function(){\n cursor.nextObject(processOne);\n };\n\n var processOne = function(err, profile){\n if(err){\n console.error("Error loading profile", err);\n getNext();\n } else if(profile == null){\n // process is done, all profiles processed!!!\n } else {\n processProfile(profile)\n .then(function(){\n getNext();\n })\n .catch(function(errProfile){\n console.error("Error processing profile", errProfile);\n getNext();\n });\n }\n };\n\n var processProfile = function(profile){\n // Complex profile processing and promise resolve when done\n };\n\n getNext();\nRun Code Online (Sandbox Code Playgroud)\n\n问题:当我有大约 300,000 个配置文件时,我得到 null(这意味着光标已耗尽),因此,只有前 300,000 个左右得到处理。\xc2\xbf有人知道如何处理它或者我提前得到 null 的原因吗?
\n