如何在猫鼬中填充嵌套数组?

时间:2020-03-18 09:44:09

标签: mongoose mongoose-populate

我想获得评论的回复。我怎样才能做到这一点? 我已经尝试过 Campground.findById(req.params.id).populate({path:“ comments”,populate:{path:“ replies”,model:“ Comment_replies”}})。exec(function(er(err,foundCampground){}。但是仍然显示结果如下。

{ author: { id: 5e710000a1a2ea22a930b085, username: 'alexandra' },
      comments:
       [ { author: [Object],
           likes: 2,
           likers: [Array],
           replies: [Array],
           _id: 5e71ac776001421205aae08c,
           text: 'Yes, truly it is!!!!',
           created_at: 2020-03-18T05:07:03.423Z,
           __v: 5 } ],
      likes: 2,
      likers: [ 5e710000a1a2ea22a930b085, 5e71b0fa1c44141882b38327 ],
      _id: 5e710512ef9ab2278dd632cb,
      title: 'Alex',
      image:
       'https://media-cdn.tripadvisor.com/media/photo-s/05/f4/f2/39/turkey-creek-campground.jpg',
      description: 'This is awesome!!',
      created_at: 2020-03-17T17:12:50.832Z,
      __v: 9 }

0 个答案:

没有答案