问题:我是否将我的子评论嵌套在单个父评论中?
概述:
创建评论系统
评论可以有孩子
现在,每个评论子项或父项都作为一个记录存储在一个名为的集合中
SubmissionCommentsSchema
子评论的键 => 值为
parent_id
=>Object ID
,其中Object ID
引用了具有parent_id
of的父评论null
。
架构看起来像:
SubmissionCommentsSchema = new Schema({
id : Schema.ObjectId,
submission_id : {
type: String
},
parent_id : {
type: String,
default: null
},
comment : {
type: String,
required: true
},
user_id: {
type: String,
required: true
},
username : {
type: String,
required: true
},
created : {
type: Date,
default: Date.now
},
reply : {
type: Boolean,
default: false,
required: true
},
deleted : {
type: Boolean,
default: false
}
});
父评论示例:
{ submission_id: '51899313634afe0000000051',
comment: 'asdfadsf',
user_id: '516e173f48670b44d20004dc',
username: 'bobcobb',
_id: 51899338634afe0000000055,
deleted: false,
reply: false,
created: Tue May 07 2013 16:50:16 GMT-0700 (PDT),
parent_id: null },
引用上述父评论的子评论示例:
{ submission_id: '51899313634afe0000000051',
comment: 'Testing one two four',
user_id: '516b45f8ac6a1b488e000001',
username: 'testing',
_id: 519d93a83867470000000146,
deleted: false,
reply: false,
created: Wed May 22 2013 20:57:28 GMT-0700 (PDT),
parent_id: '51899338634afe0000000055' },
- 在将这些提供给视图时,我将它们全部拉回并循环遍历它们以查看哪些具有
parent_id
s !==null
。如果是这样,那么我将它们放在一个列表中并将它们附加到父注释中,然后将它们转储到视图中。
我是否应该将原始父评论中的子评论存储为嵌套数组?