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
2022-01-17T11:04:55.357+00:00

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,
Santosh

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

1 answer

Sort by: Most helpful
  1. Anurag Sharma 17,591 Reputation points
    2022-01-20T06:56:39.883+00:00

    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.