问题
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