UpsertItemAsync 有一个可选参数,您可以在其中指示 PartitionKey .
UpsertItemAsync has an optional parameter where you can indicate the PartitionKey.
这是针对新" CosmosClient的,而不是针对旧" CosmosClient的.
This is for the 'new' CosmosClient and not for the 'old' DocumentClient.
docs.microsoft/en-us/dotnet/api/microsoft.azure.cosmos.container.upsertitemasync?view=azure-dotnet
如文档所述-它是可选的,因为如果您不提供该选项,它将自动从项目中提取.那不是很完美吗?
As the documentation says - it is optional because if you do not supply one, it will be automatically extracted from the item. Isn't that perfect?
在任何您不想要的情况下都有可能的情况吗?
Is there any conceivable situation under any circumstances where that is not what you want?
推荐答案因为提取PartitionKey意味着SDK需要解析该项目并弄清楚哪个是正确的属性,以及所有花费计算时间的事情.参考 github/Azure/azure-cosmos-dotnet-v3/blob/master/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerCore.Items.cs#L506
Because extracting the PartitionKey means that the SDK needs to parse the item and figure out which is the correct attribute and all that takes computational time. Reference github/Azure/azure-cosmos-dotnet-v3/blob/master/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerCore.Items.cs#L506
如果您提前知道PartitionKey值是多少,它将提高操作的整体性能.
If you know ahead of time which is the PartitionKey value, it will improve the overall performance of the operation.
更多推荐
为什么在使用CosmosClient升级项目时,为什么要显式地包含PartitionKey?
发布评论