Why would I ever want to explicitly include a PartitionKey when upserting an item with CosmosClient?

主宰稳场 提交于 2021-01-29 13:13:09

问题


UpsertItemAsync has an optional parameter where you can indicate the PartitionKey.

This is for the 'new' CosmosClient and not for the 'old' DocumentClient.

https://docs.microsoft.com/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?


回答1:


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 https://github.com/Azure/azure-cosmos-dotnet-v3/blob/master/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerCore.Items.cs#L506

If you know ahead of time which is the PartitionKey value, it will improve the overall performance of the operation.



来源:https://stackoverflow.com/questions/58216945/why-would-i-ever-want-to-explicitly-include-a-partitionkey-when-upserting-an-ite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!