I'm trying to understand this part of the API so I can update documents in the most efficient way possible.
Given the following:
Replace
" requires that a document already existsUpsert
" doesn't require that a document exists, but needs the document ID if it's going to do an update.If I always have to query the document first anyway so as to avoid wiping out any property values that aren't passed back to the upsert/replace, and I can't do a partial updates, what's the point of having both upsert and replace?
Am I missing the intended use cases for these two commands?
Upserts a Document as an asychronous operation in the Azure Cosmos DB service. UpsertDocumentAsync(Uri, Object, RequestOptions, Boolean, CancellationToken) Upserts a document as an asynchronous operation in the Azure Cosmos DB service.
It is a good choice for any serverless application that needs low order-of-millisecond response times, and needs to scale rapidly and globally.
Azure Cosmos DB is the next big leap in globally distributed, at scale, cloud databases. As a DocumentDB customer, you now have access to the new breakthrough system and capabilities offered by Azure Cosmos DB.
There are two ways you can connect to documentDB from an Azure function. DocumentClient documentClient = new DocumentClient( "SERVICE_ENDPOINT", "MASTER_KEY", ConnectionPolicy. GetDefault(), ConsistencyLevel. Session);
You've already described the key differences between the two. Upsert will create a document if it doesn't already exist otherwise overwrite it. Replace requires that a document already exist and then overwrites it. Which to use is a concern of your application. There are certain circumstances where you would want to use replace because if the document didn't already exist it would constitute an error in your business logic. Otherwise they are very similar.
I understand that the lack of being able to do a partial update can appear frustrating. However, Cosmos has a powerful server side programming model in the form of Stored Procedures which you write in Javascript. You could easily create a SPROC that receives a partial document and updates or adds only those properties that are new or changed which would give you the functionality you're ultimately looking for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With