2 回答
TA贡献1829条经验 获得超7个赞
您是否尝试在创建架构后添加“响应”字段?
const CommentSchema = new mongoose.Schema({
username: {
type: String,
required: true,
},
detail: {
type: String,
required: true,
},
});
CommentSchema.add({ responses: [CommentSchema] });
不过,我可能会这样做的方式是保留您的原始设置并将响应保存为评论模型的 ObjectId。
const CommentSchema = new mongoose.Schema({
username: {
type: String,
required: true,
},
detail: {
type: String,
required: true,
},
responses: [{ type: ObjectId, ref: 'Comment' }],
});
const Comment = model('Comment', CommentSchema);
然后只需根据需要填充“响应”字段。
TA贡献1789条经验 获得超10个赞
在您的顶部代码段中,您有responses: [CommentSchema]但 CommentSchema 仍未定义,因为此代码段正在定义它。您不能进行这种递归定义。
添加回答
举报
