蓝鸟和mongoose:警告:一个承诺是在一个处理程序中创build的,但没有被返回

我在我的项目中使用mongoose和蓝鸟。 这个警告无处不在,即使我纠正了我的所有代码。 它仍然发生。

exports.middleware = function (req, res, next, id) { Account.findById(id).exec().then(function(account) { if (!account) { return res.status(404).send({ message: 'No account with that identifier has been found' }); } req.account = account; next(); }).catch(function(err) { return next(err); }); }; 

在检查了lib / query.js的mongoose源代码后,我注意到在exec()callback函数中有一些问题

https://github.com/Automattic/mongoose/blob/master/lib/query.js#L2243

 query.prototype.exec = function exec(op, callback) { ... if (callback) { promise.then( function() { callback.apply(null, _results); }, function(error) { callback(error); }); } ... } 

()中没有任何回报。 所以在mongoose之前解决这个问题。 我只是避免在我的代码中使用exec(callback)。 那么每个人都会很高兴。