Has anyone worked with the nodejs modules 'deferred' and 'mongoose'? I'm trying to get the deferred.promisify method to work on mongoose models' functions so I can chain them easily, but running into some troubles. Specifically, I'd like to promisify the find
and findById
functions so I can chain finding one document referenced by another document by ObjectID.
Here's what I've got: https://gist.github.com/3321827
However, this seems less than ideal since the getAppPermissions
and getApplication
functions seem to be little more than wrappers for the find
and findById
methods of the mongoose model.
I tried just passing the functions to promisify, but I get an error about Object #<Object> has no method '_applyNamedScope'
which appears to be caused because this
is no longer bound to the correct object. Perhaps I need to use underscore.bind? Has anyone had any success in this area, or should I just stick with what's working now?