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

Hala Ibrahim 20 Reputation points Microsoft Employee
2023-11-15T21:32:52.55+00:00

Hi,

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
C#
C#
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 (SqlWork.com) 48,976 Reputation points
    2023-11-15T23:09:12.5266667+00:00

    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:

    https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/how-to-write-stored-procedures-triggers-udfs?tabs=javascript

    0 comments No comments