Reputation: 1093
I use mongoose and Bluebird in my project. This warning is everywhere even I correct all my code. It still happen.
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);
});
};
Upvotes: 2
Views: 277
Reputation: 1093
After I check mongoose source code of lib/query.js I noticed there is some issue in the exec() callback function
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);
});
}
...
}
There is no return in promise.then(). So before mongoose fix this issue. I just avoid to use exec(callback) in my code. then everyone will be happy.
Upvotes: 2