简体   繁体   中英

Azure Cosmos/Document DB Trigger

I am trying to put a trigger on a Collection, and it appears to not be tripping. The Trigger is prepared with the Azure Portal. I was trying specific logic - but in the end just placed an example on the Azure Site. The Trigger logic is the following:

var context = getContext();
var request = context.getRequest();

// document to be created in the current operation
var documentToCreate = request.getBody();

// validate properties
if (!("timestamp" in documentToCreate)) 
{
  var ts = new Date();
  documentToCreate["my timestamp"] = ts.getTime();
}

// update the document that will be created
request.setBody(documentToCreate);

The trigger is not working. No errors appear to be generated and I am unsure what is going on.

Note: the trigger is a pre crate trigger. And for the trigger logic I listed I am not creating a document with a "my timestamp" property. I have also tested other scenarios along the same concept where I want to add an attribute to the document being created.

Triggers are not automatically triggered. Rather, you have to explicitly specify the trigger in the operation that you want to activate the trigger. This is done for performance reasons but it makes triggers less useful.

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