I have tried to implement a delete pre-trigger in CosmosDB by using Script Explorer in Azure portal (Trigger type is "Pre" and trigger operation is "Delete" ). What I want to do is creating a new document by using the deleted one and changing its "pastDue" property as true. After deleting a document from my collection, I can't see any changes.
Could someone tell me what I am doing wrong?And how can I see if the trigger is executed successfully or not?
function markReminderAsPastDue() {
var collection = getContext().getCollection();
var request = getContext().getRequest();
var docToCreate = request.getBody();
docToCreate["pastDue"] = true;
collection.createDocument(collection.getSelfLink(),
docToCreate,
function (err, documentCreated) {
if (err) throw new Error('Error' + err.message);
});
}
Here is the function that I use to delete any document from any collection in my database handler class:
removeItem (item, partitionKey, callback)
{
var options = {
partitionKey: [ partitionKey ? partitionKey: item.email]
};
this.client.deleteDocument(item._self, options,
(err, doc) => {
if (err)
{
LogUtils.error("DBHandler.removeItem "+err.body);
callback(err, null);
}
else
{
callback(null, "success remove Item");
}
});
}