how to design MongoDB schema
来源:互联网 发布:知乎 phyton 编辑:程序博客网 时间:2024/05/22 05:29
Type of query: ask yourself what could be the best model representation for the most frequent queries you'll need to do. Everytime I'll get the parent document I'll always (or really often) need all the child documents. Answer : Nested.
2 Data model lifecycle: think about the life cycle of the container document and its content: make sense that child documents will still have to exist when the parent document is deleted? If the answer is "no" nested is the way.
3 Snapshots: another reason that should affect your choice is the data you're representing and if the nested item i s a snapshot of something happened at a given time. Suppose you're working with a "Receipt" object that contains a list of buyed products these will be copied as a nested documents in the receipt. You're storing an information related to a specific time like the product cost. So if your child documents are snapshot, pick a nested represe ntation.
4 Direct access: how many times you need to easily access the nested document (without caring of its container). If you need this, go for a flat design with references.
5 Number of nested object: a MongoDB document has a size limit of 16MB (quite big amount of data). If your subcolle ction can growth without limits go flat.
6 Rule of thumb: if the amount of data to transfer doesn't affect your client experience and the number of subdocum ents has a numerical limit, go nested, otherwise flat.
7 Embedding is better for...
8 Small subdocuments
9 Data that does not change regularly
10 When eventual consistency is acceptable
11 Documents that grow by a small amount
12 Data that you’ll often need to perform a second query to fetch Fast reads
13 References are better for...
14 Large subdocuments
15 Volatile data
16 When immediate consistency is necessary Documents that grow a large amount
17 Data that you’ll often exclude from the results Fast writes
- how to design MongoDB schema
- MongoDB Introduction, Installation and MongoDB Schema Design: How to Think Non-Relational
- MongoDB Schema Design
- MongoDB Schema Design的Slide
- MongoDB Schema Design(MongoDB模式设计)
- CPU Design HOW-TO
- How to Design Programs
- How to Use Design Patterns
- How to use design patterns
- How to Use Design Patterns
- How to design your model
- 《How to design programs》引子
- 绝好的MongoDB学习资料之三. Schema Design
- M101P: MongoDB for Developers - Chapter 3: Schema Design
- How to Use Design Patterns(转载)
- How to Use Design Patterns(ZT)
- Erich Gamma, How to Use Design Patterns
- How To Design a (module) API
- 求二叉树的宽度
- C++实现二叉树的建立和三种递归遍历
- 2014年6月编程语言排行榜
- 安卓Activity全屏的一种办法
- c++选择类型的一些经验标准
- how to design MongoDB schema
- ZOJ-1163
- 安卓背景图片移动(全屏)
- web前端开发的时候需要养成的习惯
- 人脸识别主要算法原理
- python基础教程_学习笔记18:标准库:一些最爱——shelve
- SAE下创建一个django项目
- Ubuntu12.04下安装Git
- 解决View Hierarchy不能启动