http://docs.mongodb.org/manual/core/sharding-shard-key/来自以上链接的内容.. "MongoDB generates ObjectId values upon document creation to produce a unique identifier for the object. However, the most significant bits of data in this value represent a time stamp, which means that they increment in a regular and predictable pattern. Even though this value has high cardinality, when using this, any date, or other monotonically increasing number as the shard key, all insert operations will be storing data into a single chunk, and therefore, a single shard. As a result, the write capacity of this shard will define the effective write capacity of the cluster."
2 回答
从技术上讲,您不需要对内容进行分片,只需要为您的字段编制索引即可 . 是的,您可以在日期字段上创建索引,并且可以通过访问查询计划来查看该索引 db.collection.explain("executionStats")
但是,选择分片键非常重要 . 选择分片键时要考虑的事情很少
选择日期字段实际上给出了非常高的基数,但是它无法进行随机化,因此所有文档都存储在单个分片中,因此它限制了系统的写入容量 . 出于同样的原因,不鼓励使用ObjectId作为分片键 .
http://docs.mongodb.org/manual/core/sharding-shard-key/来自以上链接的内容.. "MongoDB generates ObjectId values upon document creation to produce a unique identifier for the object. However, the most significant bits of data in this value represent a time stamp, which means that they increment in a regular and predictable pattern. Even though this value has high cardinality, when using this, any date, or other monotonically increasing number as the shard key, all insert operations will be storing data into a single chunk, and therefore, a single shard. As a result, the write capacity of this shard will define the effective write capacity of the cluster."
根据您的描述,听起来您可能不需要分片,而是按日期将大型集合拆分为较小的集合 . 因此,实时收藏仅包含最新数据,旧数据会定期移动到其自己的存档集合中 . 假设您不一起查询新旧数据,这将起作用 .