cansado2930
cansado2930

Reputation: 339

How to do a transaction with two collections on Azure CosmosDB

I have a question about transaction on Azure CosmosDB (with SQL API) where I have to edit two items on collection A and create other item on collection B.

I’m developing a project where there are exchange of points. So I have users with status of their points and I have to save the transaction for history. On a SQL database, I start a transactions, do the operation of update user A balance, update user B balance and create a new row on tickets with all details of operation and if it is good, end the transaction. But I have dudes about how to do on Azure CosmosDB. I have a collection where there are users with their balance, and other collection with tickets. So, with stored procedure, I can update user A and user B because both are on the same collection and if some of them fail to update, the collection isn’t edited (as transaction of SQL database), but, how to create the new ticket? Because If I have understood the documentation correctly, it works on same collection, but it doesn’t work with different collections.

Could you give me some advice about how to do it in order to do the 3 operations on the same transactions?

Upvotes: 1

Views: 1918

Answers (1)

Nick Chapsas
Nick Chapsas

Reputation: 7200

CosmosDB only supports transactions within the same partition.

This means that you cannot have cross containers transactions and you also cannot have transaction between 2 documents with different partition key values.

Upvotes: 4

Related Questions