簡體   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