如何在 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.
时应该处理事情
我的想法基本上是:
- 单个数据库
单个合集
两者都会自然地映射到 Cosmos 的模型以获得最便宜的体验。我的目标是 400 RU 作为标准尺寸,因为它是最便宜的选择。
多种类型的文档,每种文档都有一个 TenantID 属性,它将映射到应用程序中具有各自(安全、用户、性能等)问题的独立租户,以及DocumentType 属性 以便于过滤。
对于 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
我目前正在研究在 Azure CosmosDB 基础架构上使用 MongoDB 进行多租户多文档类型应用程序 运行。
MSFT 文档上的分区页面(即 https://docs.microsoft.com/en-us/azure/cosmos-db/partition-data)彻底解释了如果您使用 DocumentDB 与 Cosmos 通信,如何实施分区策略,但他们没有详细说明我如何使用 MongoDB API.
时应该处理事情我的想法基本上是:
- 单个数据库
单个合集
两者都会自然地映射到 Cosmos 的模型以获得最便宜的体验。我的目标是 400 RU 作为标准尺寸,因为它是最便宜的选择。
多种类型的文档,每种文档都有一个 TenantID 属性,它将映射到应用程序中具有各自(安全、用户、性能等)问题的独立租户,以及DocumentType 属性 以便于过滤。
对于 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