我正在Node.js + MongoDB数据库中创建一个博客应用程序。我以前使用像MySQL这样的关系数据库,但这是我第一次使用NoSQL数据库。所以我想在进一步发展之前遵循我的MongoDB数据模型。
我已经确定我的blogDB有3个集合
PostDB
{
_"id" : ObjectID(...),
"author": "author_name",
"Date": new Date(....),
"tag" : ["politics" , "war"],
"post_title": "My first Article",
"post_content": "Big big article"
"likes": 23
"access": "public"
}
CommentDB
{
"_id" : Objectid(...),
"POST": "My First Article",
"comment_by": "User_name",
"comment": "MY comments"
}
UserInfoDB
{
"_id": ObjectID(...),
"user": "User_name",
"password": "My_password"
}
感谢您的评论。
答案 0 :(得分:3)
在您的位置,我会将评论集合嵌入到帖子集合中。 这样做的缺点是,如果你有很多评论,你可以达到16MB的限制。 优点是您预先加入了数据,因此查询速度会更快。无论如何,你不会在没有帖子的情况下寻找评论。
另一件事是您可以将“user”字段设置为UserInfo集合的ID。这样,您将在“注释”中引用唯一用户。