如何使用.populate填充此博客文章下的评论

问题描述

我用ObjectID ref创建了模型。在我的帖子请求中回复。它填充了帖子下的评论,但是在获取请求时不起作用。请问我想念什么?


router.get('/:id',async (req,res) => {

  try {
    
    const post = await Post.findById(req.params.id)
    .populate("comments")
    
    res.send(post)

  } catch (error) {
    console.log(error)
    res.send(error)
  }
});

这是我得到的答复:它不显示评论

{
    "comments": [],"_id": "5f9d2cf2f851f6214cff96e6","title": "My First Blog Post","post": "This is the content as Edited","user": "5f9d26bf5cf5e91a6441b0e3","createdAt": "2020-10-31T09:22:58.453Z","updatedAt": "2020-10-31T09:26:01.685Z","__v": 0
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...