简体   繁体   中英

Tracking Deletions in Azure Cosmos DB/MongoDB

I am fairly new to azure cosmos db. What i am trying to do is,whenever a document is getting deleted from a collection, i want the deleted record to be inserted into a separate collection.

The easiest way to do is,insert the record at the time of deletion. But the problem is,the deletion is done by separate teams who can do it from the code or any client like mongodb compass which i dont have any control on.

I want to trigger an action that will insert the going to be deleted record to a backup collection before the actual deletion happens.

Found this link on how to do it for insertions and updations with azure functions and cosmosdb trigger.. really useful..

https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-cosmos-db-triggered-function#create-an-azure-cosmos-db-account

The best way to accomplish this is to use soft deletes with a tombstone flag in your data and then use Change Streams to detect the tombstone flag and copy it to another collection and then TTL the original record. You can learn more about using change streams on Cosmos DB's api for MongoDB here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM