COSMOS History - How to get the Old value and new value for document in COSMOS DB. Do have any alternative way achieve that?

K Chaudhari, Santosh 1 Reputation point

Hi COSMOS team,

As per bussiness requirement, I need to capture the change history. If attribute1 in document changes; that need to be recorded, old value for attribute 1 and new value for attribite1. Trying to achieve this. Please share your suggetions.

  1. Is It possible to capture those value? If yes, please guilde me.
    2, If no, suggest any alternative way to achieve this.

Thank you,

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,439 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Anurag Sharma 17,571 Reputation points

    Thanks for your patience. If we want to capture old and new values for a document, we can use Pre and Post trigger available in Azure Cosmos DB:

    How to write triggers

    For your requirement, we should go with pre-trigger where we can capture the old values of documents before they got changed.

    Create a function triggered by Azure Cosmos DB

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