分片群集
MongoDB分片群集由以下組件組成:
- 分片:每個分片包含分片數(shù)據(jù)。每個分片都可以部署為副本集。
-
mongos:
mongos充當查詢路由器,在客戶端應用程序和分片群集之間提供接口。 -
config服務器:配置服務器存儲集群的元數(shù)據(jù)和配置設置。從MongoDB 3.4開始,必須將配置服務器部署為副本集(CSRS)。
image.png
分片鍵
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.
