【发布时间】:2018-02-04 09:55:18
【问题描述】:
我正在使用 mongo,需要对循环内的每个项目进行异步调用。一旦循环内的所有承诺都完成后,我想执行另一个命令,但到目前为止,循环中的承诺似乎是在循环之后的代码之后完成的。
基本上我希望订单是
循环承诺 然后 其他代码
而不是现在的样子
其他代码 循环承诺
MongoClient.connect(connecturl)
.then((client) => {
databases.forEach((val) => {
val.collection.forEach((valcol) => {
client.db(val.databasename).stats() //(This is the async call)
.then((stats) => {
//Do stuff here with the stats of each collection
})
})
})
})
.then(() => {
//Do this stuff after everything is finished above this line
})
.catch((error) => {
}
我们将不胜感激。
【问题讨论】:
标签: javascript mongodb promise