2017-06-20 95 views
0

我试图在一个集合上放置一个触发器,它似乎不会跳闸。触发器已准备好Azure门户。我正在尝试特定的逻辑 - 但最终只是在Azure站点上放置了一个示例。触发逻辑如下:Azure Cosmos /文档数据库触发器

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); 

触发不工作。似乎没有错误产生,我不确定发生了什么。

注意:触发器是一个预置触发器。而对于我列出的触发逻辑,我并没有使用“我的时间戳”属性创建文档。我还测试了其他场景,其中我想向正在创建的文档添加属性。

回答

4

触发器不会自动触发。相反,您必须在操作中明确指定要激活触发器的触发器。这是出于性能原因而完成的,但它使触发器不太有用。

+0

究竟是如何从一次手术中绊倒?它们只能从代码触发吗?他们可以从Azure Portal绊倒吗? – Peter

+0

对于node.js SDK,您可以在任何操作的请求选项中指定它(例如,说'upsertDocument()'):http://azure.github.io/azure-documentdb-node/global.html#RequestOptions 。我怀疑其他SDK类似。 –

+0

就我所知,正如Larry Maccherone所说,我们需要在操作中明确指定触发器来激活触发器。目前,Azure门户似乎不支持它。我还发现另一个smilar [SO线程](https://stackoverflow.com/questions/32647843/trigger-in-documentdb-not-fired)。 –