【发布时间】:2016-08-30 21:00:58
【问题描述】:
我试图保留 DocumentDB 的数据历史记录(至少退一步)。
例如,如果我在文档中有一个名为 Name 的属性,其值为“Pieter”。现在我将其更改为“Sam”,我必须维护历史记录,以前是“Pieter”。
到目前为止,我正在考虑预触发。还有其他解决方案吗?
【问题讨论】:
标签: azure azure-storage azure-cosmosdb
我试图保留 DocumentDB 的数据历史记录(至少退一步)。
例如,如果我在文档中有一个名为 Name 的属性,其值为“Pieter”。现在我将其更改为“Sam”,我必须维护历史记录,以前是“Pieter”。
到目前为止,我正在考虑预触发。还有其他解决方案吗?
【问题讨论】:
标签: azure azure-storage azure-cosmosdb
Cosmos DB(以前称为 DocumentDB)现在通过更改源提供更改跟踪。使用 Change Feed,您可以侦听特定集合的更改,按分区内的修改排序。
可通过以下方式访问更改提要:
例如,这里是来自 Change Feed 文档的 sn-p,用于从 Change Feed 中读取给定分区(文档 here 中的完整代码示例):
IDocumentQuery<Document> query = client.CreateDocumentChangeFeedQuery(
collectionUri,
new ChangeFeedOptions
{
PartitionKeyRangeId = pkRange.Id,
StartFromBeginning = true,
RequestContinuation = continuation,
MaxItemCount = -1,
// Set reading time: only show change feed results modified since StartTime
StartTime = DateTime.Now - TimeSpan.FromSeconds(30)
});
while (query.HasMoreResults)
{
FeedResponse<dynamic> readChangesResponse = query.ExecuteNextAsync<dynamic>().Result;
foreach (dynamic changedDocument in readChangesResponse)
{
Console.WriteLine("document: {0}", changedDocument);
}
checkpoints[pkRange.Id] = readChangesResponse.ResponseContinuation;
}
【讨论】:
如果您尝试制作审核日志,我建议您查看事件溯源。根据事件构建您的域可确保正确的日志。见https://msdn.microsoft.com/en-us/library/dn589792.aspx和http://www.martinfowler.com/eaaDev/EventSourcing.html
【讨论】: