如何在 CosmosDB 实例中使用 mongodb 的分片

How do I use mongodb's sharding in a CosmosDB instance

我目前正在研究在 Azure CosmosDB 基础架构上使用 MongoDB 进行多租户多文档类型应用程序 运行。

MSFT 文档上的分区页面(即 https://docs.microsoft.com/en-us/azure/cosmos-db/partition-data)彻底解释了如果您使用 DocumentDB 与 Cosmos 通信,如何实施分区策略,但他们没有详细说明我如何使用 MongoDB API.

时应该处理事情

我的想法基本上是:

对于 DocumentDB API,使用 TenantID 作为 PartitionKey 是很自然的。有了 MongoDB API,我可以把它留给 Azure 吗?我应该做点什么吗'manually'?

我正在使用 C# API,如果它很重要 - 我假设配置在其他任何地方都是相似的。

Mongo 和 Cosmos 分片机制构建不同,因此如果您想充分利用平台,分片键在系统之间应该不同。

取自本网站 Mongo DB http://learnmongodbthehardway.com/schema/sharding/

Cardinality

Always consider the number of values your shard key can express. A sharding key that has only 50 possible values, is considered low cardinality, while one that might be able to express several million values might be considered a high cardinality key. High cardinality keys are preferable to low cardinality keys to avoid un-splittable chunks.

因此,在 Mongo 数据库中,您需要将高基数分区键用于大约 64MB 的目标块(逻辑分区),

在 Cosmos DB 中,您将以低基数分区键为目标,因为逻辑分区最大为 10G