我有一个注释模式,允许嵌套回复:
const mongoose = require('mongoose')
const Schema = mongoose.Schema
let Comment = new Schema({
content: {
type: String
},
user_id: {
type: String
},
user_name: {
type: String
},
_report: {
type: String,
ref: 'Report'
},
parent_comment_id: {
type: String,
ref: 'Comment'
},
reply: [{
type: mongoose.Schema.Types.ObjectId,
ref: 'Comment',
}]
}, { timestamps: true })
module.exports = mongoose.model('Comment', Comment)
这在报告模式中引用。
无论何时调用报告,我都会显示与之相关的评论。
问题是我遇到的问题是在注释中填充数量不确定的级别(因为有些人可以回复对回复的回复,等等)。
所以,我的问题是,我将如何调整它以填充无数个级别:
const report = await Report.find({createdAt: { $gt: startDate, $lt: Date() }}).sort({createdAt:-1})
.populate({path: 'like'})
.populate({path: 'comment'}) //obviously does not work right now
.populate({
path: 'player',
populate: [{ path: 'team' },
{
path: 'team',
populate: {
path: 'league'
}
}
]
})