繁体   English   中英

在Azure Cosmos DB中Upsert之前阅读

[英]Read before Upsert in Azure Cosmos DB

我很困惑Azure Cosmos DB“ UpsertDocumentAsync” C#API的工作方式。 如果您首先阅读该对象,则看起来该对象已更新:

var response = await client.ReadDocumentAsync(UriFactory.CreateDocumentUri(databaseId, collectionId, "docId"), new RequestOptions { PartitionKey = new PartitionKey("pk") });
var upsertOrder = response.Resource;
var upsertOrder = new Measurements { Id = "docId" , value = 3243};
upsertOrder.SetPropertyValue("value", 5678);
response = await client.UpsertDocumentAsync(collectionLink, upsertOrder);

相反,如果我直接创建一个对象:

 var upsertOrder = new Measurements { Id = "docId" , value = 3243};
 response = await client.UpsertDocumentAsync(collectionLink, upsertOrder);

这创建了一个新对象! 我真的受限制在修补文档之前阅读该文档吗?

编辑我知道我也需要添加partitionKey。 因此,它不再创建新对象,但是将所有未通过的字段设置为NULL。 这不是补丁行为! 所以我正确吗,我仍然需要通过所有字段?

非常感谢这里的遮阳灯。

https://feedback.azure.com/forums/263030-azure-cosmos-db/suggestions/6693091-be-able-to-do-partial-updates-on-document

如您所见,该功能是计划中的,但仅在2018年3月5日得到反馈,因此可能要过一段时间才能交付。

目前,您既可以阅读文档,进行更新,然后按照声明进行插入-部分原因是文档大小是重要的设计选择,或者您也可以编写存储过程来执行此操作并使用此功能进行部分更新。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM