【发布时间】:2018-05-07 12:51:30
【问题描述】:
我在 node.js ES6 中使用 await async ...
async insertIngot(body, callback) {
console.log('*** ItemsRepository.insertIngot');
console.log(body);
const data = await this.getItemsTest();
console.log('*** getItems ok');
items = data.items;
let item = new Ingot();
item.ingotName = body.ingotName;
item.formulaName = body.formulaName;
item.items = items;
await item.save();
return item;
}
第一个 await 有效,然后它会跳过其余代码并引发错误:
(node:16612) DeprecationWarning: Mongoose: mpromise(mongoose 的默认承诺库)已弃用,请插入您自己的承诺库:http://mongoosejs.com/docs/promises.html
【问题讨论】:
-
仅供参考,async/await 不是 ES6 的一部分。
标签: javascript node.js mongodb async.js ecmascript-2017