I've implemented mongoose with Bluebird's promisifyAll like this:
var mongoose = require('bluebird').promisifyAll(require('mongoose'))
Now, I'm trying to fetch a document from MongoDB using the "where" clause in the following code snippet:
// Retrieve list of Posts
exports.index = function(req, res) {
console.log(req.query);
Post.findAsync()
.whereAsync({author: req.query.id})
.execAsync()
.then(function(entity) {
if (entity) {
res.status(statusCode).json({
status_code: statusCode,
data: entity
});
}
})
.catch(function(err) {
res.status(200).json({
status_code: statusCode,
message: 'error occurred',
errors: err
});
});
};
However, it seems to be hanging. Am I missing something here? Any assistance on utilizing promisifyAll from Bluebird along with mongoose would be greatly appreciated. Thank you :)