How to alternate below code into Bluebird Promise style? How to alternate below code into Bluebird Promise style? mongoose mongoose

How to alternate below code into Bluebird Promise style?


UserUnit.find is not a callback method or even asynchronous so UserUnit.findAsync doesn't make sense. You shouldn't need to promisify your own classes you should just have your clasess to return promises to begin with.

If you have promisified mongoose somewhere:

Promise.promisifyAll(require("mongoose"));

You can do

UserUnit.find({ user_id: req.user._id })    .populate("unit_id")    .execAsync()    .then(function(units) {        res.json(units);    })    .catch(function(err) {        res.send(err);    });