Transactional Batch for creating multiple items

mohan b 41 Reputation points

I have a container that's created with Id as partition key.

Now I am trying to add multiple items to this container using transactionalBatch based on (new partiotionKey("type")), I am getting BadRequest with PartitionKey mismatch error.

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,264 questions
{count} votes

Accepted answer
  1. GeethaThatipatri-MSFT 23,932 Reputation points Microsoft Employee

    Hi, @mohan b Which SDK? .NET or Java? The value passed to new partitionKey() should be the value of the partition key field in the document, not the name of the field. you are attempting to pass the name of the pk field, rather than the value (although it also says the container is partitioned by id, which is confusing).
    Using id as a partition key and trying to use a transactional batch are mutually exclusive. Id as partition key means the id has to be unique in the container and transactional batches can only span across documents in the same logical partition (where the partition key value is the same). Since with id as the partition key, every document has a different partition key value you would never be able to use a transactional batch with more than one document - at which point you would rather use normal point operations. If there is a need to update multiple documents atomically in Cosmos DB it needs to be considered when choosing the data model and partition key.

    You can also check the blog on TransactionalBatch it may help:

    Please let me know if you are looking for additional details.


0 additional answers

Sort by: Most helpful