我正试图找到一种在MongoDB中无限填充的方法。我有一个posts集合,它有一个对象id的comments数组。每个注释还有一个childcomment id数组。我能够嵌套两个填充物,但是这个注释系统类似于ReDIT,因为可以有无限数量的嵌套注释。
router.get('/', (req, res) => {
Post.find()
.populate({
path: 'postComments',
populate: {
path: 'commentComments'
}
})
.sort({ date: -1 })
.then(posts => res.json(posts))
.catch(err => res.status(404)
.json({ nopostsfound: 'No posts found'}));
});
我希望找到一种方法,在那里,commentcomments的填充将继续进行尽可能多的嵌套注释。任何帮助都是非常感谢的!