分片群集
MongoDB分片群集由以下組件組成:
- 分片:每個分片包含分片數(shù)據(jù)。每個分片都可以部署為副本集。
-
mongos:
mongos
充當查詢路由器隐轩,在客戶端應(yīng)用程序和分片群集之間提供接口裁僧。 -
config服務(wù)器:配置服務(wù)器存儲集群的元數(shù)據(jù)和配置設(shè)置。從MongoDB 3.4開始劲够,必須將配置服務(wù)器部署為副本集(CSRS)。
分片鍵
MongoDB使用分片鍵在各個分片之間分發(fā)集合的文檔休傍。分片鍵由目標集合中每個文檔中存在的一個或多個字段組成征绎。
在分片集合時選擇分片鍵。分片后不能更改分片鍵的選擇磨取。分片集合只能有一個分片鍵人柿。
To shard a non-empty collection, the collection must have an index that starts with the shard key. For empty collections, MongoDB creates the index if the collection does not already have an appropriate index for the specified shard key.