代码之家  ›  专栏  ›  技术社区  ›  Bhavik Kalariya

如何在单个调用中填充多个集合

  •  0
  • Bhavik Kalariya  · 技术社区  · 6 年前

    我不能用用户名填充评论。

    postController.getFriendPosts = function(req,res) {
      var CurrentUser = req.params.currentUserID;
      console.log("CurrentUserid==>>>>>>>>>>>>>:", CurrentUser);
      userModel.findOne({_id:CurrentUser})
       .exec((err,result) => {
          if (err) {
            res.status(500).send(err);
          }
          postModel.find({'userId':{$in: result.friends}})
                   .populate('users')      //it does not work
                   .populate('comment')    //it works
                   .exec((err,posts) => {
                     if (err) {
                       res.status(500).send(err);
                     }
                     console.log("POSTS...",posts); 
                     res.status(200).send(posts);
                   })
       })
    }
    
    0 回复  |  直到 6 年前
    推荐文章