Some background information
I have a Cosmos database using the sql api. In here I have a document that looks like this:
{
"id": "123",
"city": "myCity",
"address": "myAddress"
}
id
is used for the id and city
is used for partitionKey.
Suppose I do an Upsert and pass the object below as the payload and the value "myCity"
as the partitionKey, will it insert a new document or will it update the already existing one?
{
"id": "123",
"city": "anotherCity",
"address": "myAddress"
}
In .net the Upsert could look something like this
await myRepository.UpsertItemAsync(myObject, "myCity");
The question
Does an Upsert into a CosmosDB container only have to match on ID or does it have to match on both ID and PartitionKey do perform an Update?
CodePudding user response:
Does an Upsert into a CosmosDB container only have to match on ID or does it have to match on both ID and PartitionKey do perform an Update?
It will have to match both Id and PartitionKey to perform an update. Combination of Id and PartitionKey is a unique identifier for a document in a Cosmos DB container.