c# - 检测更改提要中的单个文档属性更改
问题描述
我有一个文档类型 State 用于保存当前和历史“状态”数据。每次当前状态中的属性发生更改时,我都会向 States 集合添加一个新文档,因此会随着时间的推移创建状态的“快照”。
我想知道是否可以使用 Change Feed 和 CosmosDBTrigger 来检测 State 的各个属性的更改,以便我可以根据更改触发代码。
像这样的东西:
[FunctionName("StateChangeTrigger")]
public static void Run([CosmosDBTrigger(
databaseName: "mydb",
collectionName: "States",
ConnectionStringSetting = "CosmosDB",
LeaseCollectionName = "leases",
CreateLeaseCollectionIfNotExists = true)]IReadOnlyList<Document> documents, ILogger log)
{
if (documents != null)
{
Document currentDoc = documents[documents.Count-1];
Document previousDoc;
if (documents.Count == 1)
{
previousDoc = // Fetch previous document from database, based on timestamp
}
else
{
previousDoc = documents[documents.Count-2];
}
if (currentDoc.MyProperty != previousDoc.MyProperty) // Doesn't work but you get my drift
{
log.LogInformation("Property 'MyProperty' has been modified");
// Do something
}
}
}
触发 CosmosDBTrigger 后,显然我们知道集合中有一个附加项,但我们并不确切知道哪些属性发生了变化。示例代码是处理此问题的有效方法吗?或者,还有更好的方法?
提前致谢!
解决方案
推荐阅读
- php - 使用 REST API 和大数据集时最好的方法是什么
- apache - 禁用 Apache 多个选项的问题
- python - 为什么ffmpeg警告“输入流#0.0的猜测通道布局:单声道”?
- ruby - 如何在 ruby 中获得不同包的唯一版本
- spring - DAO 构造函数中 JDBC 模板的 NullPointerException
- web-scraping - 使用scrapy进行网页抓取。不改变分页的 URL
- angularjs - ng-repeat 仅显示条件下的第一次出现
- jquery - 带有id的jQuery表单提交,serializeArray无法获取输入数据
- javascript - Cesium JS椭球切面计算
- configuration - 有谁知道如何配置 PMIC-CS5484 功率测量 IC?