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