Home > Mobile >  Cosmos DB transactional Batch
Cosmos DB transactional Batch

Time:11-23

How do I execute a select statement (Select Product from Products Where ProductID =8 ) and the perform a insert to the db in a Transactional batch statement for Cosmos DB using .net/ c#

Is there any workaround to run a select statement as a part of batch before inserting a document to cosmos DB.

I could not find how to use transactional Batch to replace my existing stored proc. having select as well as insert statements.

My Stored Procedure:

-BEGIN line 1 : Read the data from Db and take count of Products. For ex: returns 12 products.

Line 2 : Some further logic.

Line 3 : Insert record to the same table with a counter log of products ie. 12 1, returned from line 1.

-END

Now the problem that I will face if I move the first statement out of the SP , Maybe 2 or multiple instances can request the same line and get it executed . And the result I will have is Duplication of log number in products.

CodePudding user response:

You can't enlist a query into a transaction. The way to do this is to read the data then use optimistic concurrency control on the update with the etag on the item. You can find a sample here

  • Related