Azure Cosmos/Document DB触发器

Pet*_*ter 1 azure azure-cosmosdb

我试图在一个集合上设置一个触发器,它似乎没有绊倒.触发器是使用Azure门户准备的.我正在尝试特定的逻辑 - 但最后只是在Azure站点上放置了一个示例.触发器逻辑如下:

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);
Run Code Online (Sandbox Code Playgroud)

触发器无效.似乎没有出现错误,我不确定发生了什么.

注意:触发器是预先设置的触发器.对于我列出的触发器逻辑,我没有使用"my timestamp"属性创建文档.我还测试了相同概念中的其他场景,我想在创建的文档中添加属性.

Lar*_*one 6

触发器不会自动触发.相反,您必须在操作中明确指定要激活触发器的触发器.这样做是出于性能原因,但它使得触发器不那么有用.