可以限制 Cosmos DB 触发器仅对插入操作生效吗?

huangapple go评论72阅读模式
英文:

Will it be possible to limit Comos DB trigger for insert operation?

问题

我遇到了一个情况,在这种情况下,我应该更新 Cosmos DB 中的状态,但我确实为 Cosmos DB 容器设置了一个触发器。这意味着,如果我更新/插入状态,触发器将被触发(因为容器将发生变化),并且这将导致无限循环。有没有可能的方法来解决这个问题呢?

英文:

I'm having a condition where I'm supposed to update the status inside Cosmos DB, but I do have a trigger for Cosmos DB container. That means, if I update/insert the status, trigger will be fired (because container will change) and it will cause the infinite loop. Any possible ways to solve this problem please?

答案1

得分: 0

如果您在 Cosmos DB 中指的是预触发器或后触发器,它不会导致无限循环。因为它们需要使用代码来调用,就像这样:

RequestOptions requestOptions = new RequestOptions(); 
requestOptions.setPostTriggerInclude(Arrays.asList("trgPostUpdateMetadata")); 
asyncClient.createDocument(containerLink, item, requestOptions, false).toBlocking();

如果您在更新/插入作业状态时没有使用 requestOptions.setPostTriggerInclude(Arrays.asList("trgPostUpdateMetadata"));,触发器将不会被调用。

如果您指的是 Azure 函数中的 Azure Cosmos DB,请将其禁用,然后更新/插入作业状态。

英文:

If you mean pre-triggers or post-triggers in cosmos db,it won't cause the infinite loop.Because they need to invoke with code,like this:

RequestOptions requestOptions = new RequestOptions(); requestOptions.setPostTriggerInclude(Arrays.asList("trgPostUpdateMetadata")); asyncClient.createDocument(containerLink, item, requestOptions, false).toBlocking();

If you update/insert the job status without requestOptions.setPostTriggerInclude(Arrays.asList("trgPostUpdateMetadata"));,the trigger won't be invoked.

If you mean azure cosmos db in Azure Function,just disabled it then update/insert job status.

答案2

得分: 0

如果您指的是Azure Functions的Cosmos DB触发器,目前无法区分插入和更新之间的事件。

如果您有一个CreatedTime属性,您可以检查它是否与文档的时间戳(_ts属性)匹配,但无法确定事件的起始操作。

英文:

If you mean the Cosmos DB Trigger for Azure Functions, no, currently there is no way to distinguish the event between an insert and an update.

It might be possible if you have a CreatedTime property that you can check to see if it matches the document Timestamp (_ts property) but nothing that can say the originating operation for the event.

huangapple
  • 本文由 发表于 2020年9月4日 15:33:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/63736771.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定