简体   繁体   English

在Azure Cosmos DB中Upsert之前阅读

[英]Read before Upsert in Azure Cosmos DB

i am confused how Azure Cosmos DB "UpsertDocumentAsync" C# API works. 我很困惑Azure Cosmos DB“ UpsertDocumentAsync” C#API的工作方式。 Looks that the object is updated if you first read it: 如果您首先阅读该对象,则看起来该对象已更新:

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);

If instead i directly create an object: 相反,如果我直接创建一个对象:

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

this create a new object!! 这创建了一个新对象! Am i really constrained to read the doc before patching it?? 我真的受限制在修补文档之前阅读该文档吗?

EDIT I understand i need to add the partitionKey too. 编辑我知道我也需要添加partitionKey。 So it does not create a new object anymore BUT it sets all the non-passed field to NULL. 因此,它不再创建新对象,但是将所有未通过的字段设置为NULL。 This is not a patch behavior! 这不是补丁行为! So am i correct i need to pass all fields anyway? 所以我正确吗,我仍然需要通过所有字段?

thanks lot to shade lights here. 非常感谢这里的遮阳灯。

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

As you can see the feature is planned but only got feedback on Mar 5, 2018 so it may be a while until delivery. 如您所见,该功能是计划中的,但仅在2018年3月5日得到反馈,因此可能要过一段时间才能交付。

For the moment you can either read the document, update it, then insert as you have stated - part of the reason document size is an important design choice, or you could also write a stored procedure to do this and use this do partial updates. 目前,您既可以阅读文档,进行更新,然后按照声明进行插入-部分原因是文档大小是重要的设计选择,或者您也可以编写存储过程来执行此操作并使用此功能进行部分更新。

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

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