首页 > 解决方案 > mongosh 中的 Promise 或 async/await?

问题描述

我有一个应该同步执行的 mongosh 脚本。我可以在 mongosh 中使用 Promise 或 async/await 吗?好像我做不到。有没有办法确保事情不会乱序执行?

例如

(1) db.clients.find({}).forEach((client) => {
  db.addresses.insertMany([
    { ....
    }

(2) db.addresses.find({}).forEach...

当 1 仍在循环时, 2 由 mongosh 执行。有什么想法吗?

标签: mongodb-shell

解决方案


推荐阅读