【问题标题】:Understanding NoSQL Data Modeling - blog application了解 NoSQL 数据建模 - 博客应用程序
【发布时间】:2013-06-25 05:38:13
【问题描述】:

我正在 Node.js + MongoDB 数据库中创建一个博客应用程序。我以前使用过像 MySQL 这样的关系数据库,但这是我第一次使用 NoSQL 数据库。所以我想在我进一步行动之前符合我的 MongoDB 数据模型。

我已经决定我的 blogDB 有 3 个集合

  1. post_collection - 存储有关该文章的信息
  2. comment_collection - 在文章中存储有关 cmets 的信息
  3. user_info_collection - 包含用户信息

后数据库

{
  _"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"
}

评论数据库

{
   "_id" : Objectid(...),
   "POST": "My First Article",
   "comment_by": "User_name",
   "comment": "MY comments"
}

用户信息数据库

{
   "_id": ObjectID(...),
   "user": "User_name",
   "password": "My_password"
}

我会很感激你的 cmets。

【问题讨论】:

标签: node.js mongodb database nosql


【解决方案1】:

在你的位置,我会将 Comments 集合嵌入到 Posts 集合中。 这样做的缺点是,如果您有很多 cmets,您可能会达到 16MB 的限制。 优点是您预先加入了数据,因此查询会更快。无论如何,您不会寻找没有帖子的评论。

另一件事是您可以将“用户”字段设置为 UserInfo 集合的 ID。这样,您将在评论中引用唯一用户。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-06
    • 2011-05-06
    • 1970-01-01
    • 2013-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-07
    相关资源
    最近更新 更多