bluebird的populateAsync怎么使用呢?

这样写代码会报错:

 PostModel.findAsync({author:author}).populateAsync('author')
            .then(function (posts) {
                res.render('posts', {
                    posts: posts
                });
            })
            .catch(next);

错误为:

clipboard.png

bluebird这个库的populate是怎么用的呢?

阅读 2.7k
3 个回答
  • PostModel.find is not a callback method or even asynchronous so PostModel.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

PostModel.find({author: author })
    .populate("author")
    .execAsync()
    .then(function(posts) {
        res.render('posts', { posts: posts  });
    })
    .catch(next);
  • populate is not a function of bluebird, it's one of mongoose

  • Reference from here

自己顶一下啊 真的不知道怎么搞了

谢邀,没玩过这个库。那我来盲debug好了,23333

那个findAsync 是你自己封装的方法么,这个方法的执行结果返回的是啥?返回结果中有没有populateAsync这个方法?报错说返回结果没populateAsync这个方法

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题