MongoDB:用于用户和活动的嵌入式或规范化数据模型 [英] MongoDB: Embedded or Normalized Data Models for Users and Activities

查看:71
本文介绍了MongoDB:用于用户和活动的嵌入式或规范化数据模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为一个新项目设计数据库模型,由于我来自SQL世界,因此不确定哪种方法更好.

I'm designing the models of my database for a new project and since I come from the SQL world I'm not sure which approach is better.

这是我的主要恋情:

  • 用户组织的活动. (例如:约翰正在组织一场足球 游戏)
  • 加入活动"的用户. (例如:安娜和罗伯加入了约翰组织的足球比赛)
  • 活动属于类别/ActivityType(约翰的游戏属于足球类别)
  • 用户在完成活动后对其他用户进行评分(例如:约翰将他们的表现评为安娜(5星),罗伯(Rob)将其5星 在足球比赛中).
  • Activities organized by Users. (e.g.: John is organizing a Soccer game)
  • Users who join Activities. (e.g.: Anna and Rob joined the Soccer game John has organized)
  • Activities belong to a category/ActivityType (John's game belongs to the Soccer category)
  • Users rate other users after completing the activity (e.g.: John rates Anna with 5 stars and Rob with 5 stars for their performance during the Soccer game).

伪代码如下:

  1. 用户

  • _id
  • 全名
  • 电子邮件
  • 密码
  • loc({lon:X,lat:Y})
  • 活动(活动数组)
  • average_rate
  • created_at
  • updated_at

费率

  • _id
  • 时间戳
  • 活动(活动)
  • rater_user(用户)
  • rated_user(用户)
  • created_at
  • updated_at

ActivityType

  • _id
  • 名称
  • 半径

活动

  • _id
  • 类型(ActivityType)
  • 组织者(用户)
  • loc({lon:X,lat:Y})
  • 地址
  • 时间
  • max_participants
  • 说明
  • 参与者(用户数组)
  • 请求(用户数组)
  • created_at
  • updated_at
  • _id
  • type (ActivityType)
  • organizer (User)
  • loc ({ lon: X, lat: Y })
  • address
  • time
  • max_participants
  • description
  • participants (Array of User)
  • requests (Array of User)
  • created_at
  • updated_at

我应该从这种规范化方法转向嵌入式数据模型吗?

Should I moved from this normalized approach to embedded data models?

推荐答案

以下是有关在我编写的mongodb中嵌入或引用的答案.强烈建议.

Here is an answer about embedding or reference in mongodb I wrote. It's highly recommended.

用于BI的MongoDB

嵌入更适合:

  • 小的子文档
  • 数据不会定期更改
  • 可接受最终一致性时
  • 少量增长的文档
  • 您经常需要执行第二次查询才能获取的数据
  • 快速阅读速度
  • Small subdocuments
  • Data that does not change regularly
  • When eventual consistency is acceptable
  • Document that grow by a small amount
  • Data that you'll often need to perform asecond query to fetch
  • Fast reading speed

参考更适合

  • 大子文档
  • 易失数据
  • 需要立即保持一致
  • 文档大量增长
  • 您经常从文档中排除的数据
  • 快速写入速度
  • Large subdocuments
  • Volatile data
  • When immediate consistency is necessary
  • Document grow with a large amount
  • Data that you often exclude from document
  • Fast write speed

-摘自《 Mongodb权威指南》

-From 《Mongodb Definitive Guide》

这篇关于MongoDB:用于用户和活动的嵌入式或规范化数据模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆