Commit and Rollback - Node js code sample

Md. Ruhul Amin Khan 41 Reputation points

I am looking for a solution as a issue I am struggling in my node js project. I am simply want to perform a commit and rollback in a stored procedure. Like - We have 3 collections in cosmos db, if we saved data in 2 collections in database and third collection data get failed to saved then we want to rollback the current data from previous two collection from cosmos db.

Is there any way in cosmos db , so that we can rollback our changes?

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

Accepted answer
  1. Anurag Sharma 17,386 Reputation points

    Hi @Md. Ruhul Amin Khan , welcome to Microsoft Q&A forum.

    It seems that you want to achieve commit and rollback transactions across the Azure Cosmos DB multiple containers.

    Currently Stored Procedure in Cosmos DB are scoped to a single logical partition key, that means any transaction within a partition key of a container can only be rolled back. Even within the same container with different partition keys rollback would not work.

    We need to implement this manually through code only. As an example we can follow below steps:

    1. Update first collections with stored procedure and keep the record of updated items.
    2. Update second collection with stored procedure and return error message in case the procedure fails. Then undo the operation that we did in the first collections.

    Please let us know if this helps or else we can discuss further.


    If answer is helpful please click on 190809-image.png as it could help other members of the Microsoft Q&A community who have similar questions and are looking for solutions. Thank you for helping to improve Microsoft Q&A!

    0 comments No comments

0 additional answers

Sort by: Most helpful