【发布时间】:2018-03-23 06:27:27
【问题描述】:
我目前正在尝试将 Promises 与 Mongoose 一起使用。 我已经读到,从 4.1 开始,添加了 mPromise 以及插入外部 Promise 库(如 bluebird 或 q)的能力。
我对只需要然后捕获的基本承诺没有任何问题,但是,当我尝试使用 Bluebird 方法 finally 时,我最终无法这样做,并出现上述错误。这是一个代码sn-p:
mongoose.connect(uri, { useMongoClient: true, promiseLibrary: require('bluebird')})
.then(() => {
MyModel.find(query).exec()
.then(res => resolve(res)
.catch(err => reject(err))
.finally(() => {
mongoose.connection.close();
});
})
.catch(err => console.error(err));
我还确定需要蓝鸟
var Promise = require('bluebird');
var mongoose = require('mongoose');
mongoose.Promise = Promise;
知道为什么 mongoose 不返回 Bluebird 承诺吗?
谢谢
【问题讨论】:
标签: javascript node.js mongoose promise bluebird