Steffen Mangold
Steffen Mangold

Reputation: 1144

Use of [x-ms-documentdb-partitionkey] on create

Can somebody explain to me for what the x-ms-documentdb-partitionkey is used at a create document call?

What I see from the exception I notice that it has to be the same as the one extracted from the document itself.

For example c#:

_container.CreateItemAsync<Data>(data, partitionKey: new PartitionKey($"some_key"));

Clear up: I do understand how partitions keys working. I only don't get why I can put this parameter on a create command (not query!) when it is still extracted from the document.

Upvotes: 0

Views: 190

Answers (1)

Alex
Alex

Reputation: 18526

My guess would be that this is a backend/server requirement. CosmosDB does its internal routing to the compute resources based on the partition key header. They don't need to look at the actual document for this. On the other hand, the document still needs to contain the partition key value - probably because it is very natural in most cases. Supporting a scenario where the partition key value would not be part of the document is probably not desired.

This explains why the header exists.

The SDK documentation seems to suggest that the partition key is being set automatically when omitted by the code. This is probably a client side feature. May also be a configuration error or SDK bug if it does not work for you.

Maybe you find something helpful in the SDK sources.

Upvotes: 1

Related Questions