【发布时间】:2013-05-18 09:50:23
【问题描述】:
问题:我是否将我的子 cmets 嵌套在单个父评论中?
概述:
创建评论系统
评论可以有孩子
现在,每个评论子项或父项都作为一条记录存储在名为
SubmissionCommentsSchema的集合中子 cmets 的键 => 值为
parent_id=>Object ID,其中Object ID引用具有parent_id或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_ids !==null。如果是这样,那么我将它们放在一个列表中并将它们附加到父评论中,然后将它们转储到视图中。
我是否应该将原始父注释中的子 cmets 存储为嵌套数组?
【问题讨论】:
-
嗨,鲍勃,你最后用的是什么?
-
@ParagJadhav 我最终将 Sequelize.js 与 Postgres 一起使用。
标签: mongodb database-design mongoose database nosql