How to batch items with different partition keys in Cosmos DB ?

Hala Ibrahim 20 Reputation points Microsoft Employee


I want to batch items (update them all in one single operation) in cosmos DB.
The items are in the same container but have different partition keys..
Any idea ?
CreateTransactionalBatch has limitation of using same partitionKey..
any other alternative?

Thanks in advance

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,272 questions
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
9,509 questions
0 comments No comments
{count} votes

1 additional answer

Sort by: Most helpful
  1. Bruce ( 48,976 Reputation points

    a cosmos db is made up of partitions. each partition may be on separate server. atomically updating two partitions would require cross server two phase commit, and would break the Comos DB response time commitments.

    as a Transaction Batch is an atomic operator by definition, it can not cross partitions. if you don't need an atomic transaction, then

    you don't specify your requirements. you could write a cosmos db stored procedure that you passed the batch items to, and it could insert non-atomically.

    note: stored process are easier to write, if you create async wrappers for the api calls. see:

    0 comments No comments