【发布时间】:2017-05-11 07:11:13
【问题描述】:
我有两个来自 mongoose 的回调函数,我想使用 bluebird 的 then 链接它们
我的第一个回调函数成功使用then。
User.findOne().distinct(('Friends.id'), {id: req.body.myId}, {Friends: {$elemMatch: { gender: req.body.gender}}})
.then(function(IDs){
var results = //////some computation
})
.catch(function(error)) {
}
我只是无法正确链接第二个回调函数的语法,以便它共享第一个回调函数的 catch 方法。在这种情况下,我不能使用Promise.all,因为第二个回调函数依赖于第一个回调函数的results。无论如何,第二个回调函数如下:
User.find({Friends: { $not: { $elemMatch: { id: req.body.myId }}}, id: {$in: results}}, function(err, users){
})
【问题讨论】:
标签: node.js mongodb mongoose promise bluebird