我已使用 CosmosDB 触发器模板创建了一个 Azure 函数,如下所示:this link
工作正常,我可以看到更新从我在 Cosmos DB 中创建的集合中流入。
现在的问题是,我只想要那些有实际更新的文档。目前,如果我使用代码更新文档,它会更新它的时间戳并且文档正在更新。虽然没有实际的数据更新。
我的问题:
- 如何才能只获取实际更新的文档(仅那些 json 字段被修改的文档)?
- 我怎样才能跟踪已删除的文档?他们也不在这里流动?
最佳答案
1) 由于对文档的任何推送都会更新 - 内部管理 - _ts
属性,这仍然是对整个文档的更改。如果您更改了文档的用户数据,这里也没关系。变更提要不知道这种区别。因此,您也将始终在更改源中看到这些更新。
2) 删除不会添加到更改源中,但有一个可能的解决方法:
Currently change feed doesn’t log deletes. [...] you can add a soft marker on the items that are being deleted, for example, you can add an attribute in the item called "deleted" and set it to "true" and set a TTL on the item, so that it can be automatically deleted.
https://learn.microsoft.com/en-us/azure/cosmos-db/change-feed#change-feed-and-different-operations
关于Azure CosmosDB 数据触发器不进行实际更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56753458/