question

bingodk-2905 avatar image
0 Votes"
bingodk-2905 asked bingodk-2905 commented

Cosmos document update in Java, has no failure response although it indeed fail

I use the Java outputItem.setValue(doc) to update existing doc, from Function APP.
I have two such functions in parallel.
Both update calls has no exception, and no failure return (it is void...), but only one of those calls
actually updated the document.

I wonder how can it be?
Do I miss something?
update of document can fail for several reasons (i.e old doc with old etag).

By the way same problem exist when using direct CosmosContainer object to update document. - container.upsertItem(doc)

azure-functionsazure-cosmos-db
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @bingodk-2905, welcome to Microsoft Q&A forum.

Would it be possible for you to share the code you are using?

0 Votes 0 ·
bingodk-2905 avatar image
0 Votes"
bingodk-2905 answered

I use Java in FunctionApp.
I use output binding to update documents.

I use about this code in the Function:
@FunctionName("name")
public HttpResponseMessage run(
@HttpTrigger(name = "req",
methods = {HttpMethod.POST, HttpMethod.GET},
authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,

         //get all session elements by the partitionKey
         @CosmosDBInput(name = "databasein",
         databaseName = "dbname",
         collectionName = "collectionname",
            
         sqlQuery = "select * from c where c.sessionID ... ", //WORKING !!!

         connectionStringSetting = "ConnectionStringSetting")       
         Object[] inputItems,  
            
         @CosmosDBOutput(name = "databaseout",
         databaseName = "dbnabe",
         collectionName = "collectionname",//sessions
         connectionStringSetting = "ConnectionStringSetting")            
         OutputBinding<String> outputItem, //outputItem holds reference to the BingoSessions container
           
         final ExecutionContext context) 
 {
         . . .

and then I use
outputItem.setValue(documentString);
to create or update document.
}

It is partially working.
I DON'T GET ANY FEEDBACK (error, exception or even log), to know whether operation succedded or failed.
Only when I inspect the cosmosdb container, I can see if it was success or not.

When it fails, I have no idea why.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

bingodk-2905 avatar image
1 Vote"
bingodk-2905 answered bingodk-2905 commented

I found something interesting:
It is wrong to call outputItem.setValue(collection) several times in Function (as I did, in order to update several documents) !
Only last call will be executed.

The proper way is to concat all items to one json list of items and call it once.
outputItem.setValue( [ collection1, collection2, ...]

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello @bingodk-2905 - Thanks for sharing! Did it work for you? If so, please consider marking your reply above as the Accepted Answer so that your experience may benefit others who visiting here with similar queries.

0 Votes 0 ·

Hello @MikeUrnun
My finding solved secondary mistake of calling outputItem.setValue(doc) several times in a function,
However, I still don't have solution how to know if outputItem.setValue(doc) was successfull or not.

0 Votes 0 ·