Mongodb 数据模型概念

数据模型概念


Opeational Factors and Data Models

  • lifecycle management
  • indexing
  • horizontal scalability
  • docoument growth

GridFS

    GridFS is a specification for storing document that exceeds the BSON-doucument size limit of 16M.

 

数据模型设计


Embedded Data Models

以下情况下,使用embedded 数据模型:

  • you have “contains”relationships  between entities.  One-to-One relationship
  • you have one-to-many relationships between entities. In these relationships the “many” or child documents always appear with or are viewed in the context of the “one”or parent documents. One-to-Many relationships

 

Normalized Data Models

以下情况下,使用normalized 数据模型:

  • when embedding would result in duplicaton of data but would not provide sufficient read performance adavantages to outweigh the implications of the duplication.
  • to represent more complex many-to-many relationships.
  • to model large hierarchical data sets.

 

影响因子和数据模型

Document Growth

For MMAPv1, if the document size exceeds the allocated space for that document, MongoDB will reallocate the document on disk.

Atomicity

In MongoDB, operations are atomic at the document level.

Sharding

MongoDB uses sharding to provide horizontal scaling.These clusters support deloyments with large data sets and high-throughput operations.

To distribute data and application traffic in a sharded collection, MongoDB uses the shard key.

Indexes

Uses indexes to improve performance for common queries. Build indexes on fields that apper offten in queries and fro all operations that return sorted results.

The negative influence of creating indexes:

  • Each index requires at lease 8KB of data space.
  • Adding an index has some negative performance impact for writing operations. For collections with high write-to-read ratio, indexes are expensive since each insert must also update any indexes.
  • Each index consumes disk space and memory. This usage can be significant and should be tracked for capacity planning, especially for concerns over working set size.

Large Number of Collections

Data Lifecycle Management

The Time to Live or TTL feature of collections expires document after a period of time. Consider using the TTL feature if your application requires some data to persist in the database for limited period of time.

If your application only use recently inserted documents, consider Capped Collections. It provide FIFO management of inserted documents.

GridFS

GridFS is specification for storing and retrieving files that excced the BSON-document size limit of 16M.

Instead of storing a file in a single document, GridFS divides a file into parts, or chunks and stores each of those chunks as separate document. By default  GridFS limits chunk size to 155k. GridFS uses two collections to store files. One collection stores the file chunks, and the other stores file metadata.

Implement GridFS

GridFS Collections

GridFS Index

Additional Resources

转载于:https://www.cnblogs.com/hotbaby/p/4866994.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值