如何为博客设计MongoDB?

时间:2016-03-02 09:26:18

标签: mongodb database-schema

我正在为多个users构建一个简单的博客系统,他们可以通过userIDusernamenodeID(博客)访问数据。

在RDBMS中,通常我们会有user / table / ownership个表。在mongoDB中,有些人建议将它们放在一个users集合中。但是,据我所知,如果users想要访问特定的nodeID,可能会非常慢,因为mongoDB可能会遍历每个文档。在我的情况下,索引会显着降低创建速度,这意味着createUser()createNode(),对吗?

因此,我们可以遵循“最佳实践”吗? 感谢。

1 个答案:

答案 0 :(得分:2)

Three Collections Inside the DB, Namely,

"Users", 
"UserPosts", 
"UserComments"

Users Collection's Field could be

"name",
"age",
"occupation",
"profileImage",
"numberOfPosts", 
"birthdate", 
"joiningDate", 
"session"

etc.

UserPosts Collection's Field could be

    "Id", 
    "revisionId",
    "author",
    "type",
    "language",
    "userId",
    "status",
    "title",
    "tags",
    "content"

etc.

UserComments Collection's Field could be

    "Id", 
    "userPostId",
    "author",
    "type",
    "language",
    "userId",
    "status",
    "comment",

etc.

User Comment will be maintained by UserPostId Field It contains.