如何设计一个MongoDB的博客?
How to design a MongoDB for blog?
我正在为多个 users
构建一个简单的博客系统,他们可以通过 userID
、username
和 nodeID
(博客)访问数据。
在 RDBMS 中,通常我们会有 user
/table
/ownership
个表。在 mongoDB 中,有人建议将它们放在一个 users
集合中。但是,据我所知,如果 users
想要访问特定的 nodeID
,它可能会非常慢,因为 mongoDB 可能会遍历每个文档。索引会显着降低创建速度,在我的例子中,这意味着 createUser()
和 createNode()
,对吗?
所以,有什么"Best Practices"可以跟进吗?
谢谢。
三个Collections在DB里面,即
"Users",
"UserPosts",
"UserComments"
用户 Collection的字段可能是
"name",
"age",
"occupation",
"profileImage",
"numberOfPosts",
"birthdate",
"joiningDate",
"session"
等等
UserPosts Collection 的字段可能是
"Id",
"revisionId",
"author",
"type",
"language",
"userId",
"status",
"title",
"tags",
"content"
等等
UserComments Collection 的字段可能是
"Id",
"userPostId",
"author",
"type",
"language",
"userId",
"status",
"comment",
等等
用户评论将由 UserPostId 字段维护它包含。
我正在为多个 users
构建一个简单的博客系统,他们可以通过 userID
、username
和 nodeID
(博客)访问数据。
在 RDBMS 中,通常我们会有 user
/table
/ownership
个表。在 mongoDB 中,有人建议将它们放在一个 users
集合中。但是,据我所知,如果 users
想要访问特定的 nodeID
,它可能会非常慢,因为 mongoDB 可能会遍历每个文档。索引会显着降低创建速度,在我的例子中,这意味着 createUser()
和 createNode()
,对吗?
所以,有什么"Best Practices"可以跟进吗? 谢谢。
三个Collections在DB里面,即
"Users",
"UserPosts",
"UserComments"
用户 Collection的字段可能是
"name",
"age",
"occupation",
"profileImage",
"numberOfPosts",
"birthdate",
"joiningDate",
"session"
等等
UserPosts Collection 的字段可能是
"Id",
"revisionId",
"author",
"type",
"language",
"userId",
"status",
"title",
"tags",
"content"
等等
UserComments Collection 的字段可能是
"Id",
"userPostId",
"author",
"type",
"language",
"userId",
"status",
"comment",
等等
用户评论将由 UserPostId 字段维护它包含。