Cosmos DB API for MongoDB: Transaction support on multiple collections

MikeZheng-3371 46 Reputation points
2022-02-25T16:25:38.093+00:00

Hello,

We're using the Cosmos DB API for MongoDB. I just wonder how can we do the transactions on multiple collections, what is the best practice?

Thanks,

Mike

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,726 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Oury Ba-MSFT 20,006 Reputation points Microsoft Employee
    2022-02-25T19:29:40.697+00:00

    Hi @MikeZheng-3371Thank you for posting your question on Microsoft Q&A and for using Azure services.

    From my understanding you are trying to do transactions on multiple collections.
    Multi-document transactions are supported within an unsharded collection in API version 4.0. Multi-document transactions are not supported across collections or in sharded collections in 4.0.
    All drivers that support wire protocol version 4.0 or greater will support Azure Cosmos DB API for MongoDB multi-document transactions.

    https://learn.microsoft.com/en-us/azure/cosmos-db/mongodb/use-multi-document-transactions

    Regards,
    Oury


  2. Oury Ba-MSFT 20,006 Reputation points Microsoft Employee
    2022-03-01T22:24:54.323+00:00

    @MikeZheng-3371
    *What is the alternative solution? *
    Restructuring the data to be within one collection or implementing the rollback logic on the applications side would be two options.

    Regards,
    Oury

    0 comments No comments

  3. MikeZheng-3371 46 Reputation points
    2022-03-02T17:38:32.83+00:00

    Would you please provide an example of implementing the rollback logic on the application side? It is impossible for us to have ONLY one collection in the system.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.