我正在编写一个小嵌套的评论系统。我已遵循此mongoDB案例研究http://docs.mongodb.org/ecosystem/use-cases/storing-comments/中有关存储注释的规则。我选择将每个评论存储在一个文档中。
在我的界面中,我要求讨论,我在API的讨论中得到了一系列有序的评论。问题是,我非常坚持使用嵌套注释构造某种对象,以了解级别,以便我可以使用AngularJS进行渲染。 我知道如果我有一个大的JSON或对象与整个讨论和嵌套到他们的父母的回复,我可以很容易地渲染它。所以我的架构看起来像:
var CommentSchema = new Schema({
discussion_id: SchemaTypes.ObjectId,
parent_id: SchemaTypes.ObjectId,
slug: String,
full_slug: String,
community: {type: String, default: 'defaultCommunity'},
inserted: {type: Date, default: Date.now},
title: String,
text: String,
author: {
id: SchemaTypes.ObjectId,
twitter_id: SchemaTypes.Long,
twitter_screen_name: String,
twitter_profile_pic: String
},
updated: {type: Date, default: Date.now},
hearts: {type: Number, default: 0},
dislikes: {type: Number, default: 0},
flags: {type: Number, default: 0},
});
因此,当我从客户端恢复讨论时,我会收到一个数组,其中包含代表所有注释的所有文档。 slug代表评论的“路径”,例如:
我希望有人可以对此有所启发,因为我真的被困了。简单的解决方案是将整个讨论存储在一个文档中,但我想这样做。
非常感谢。