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

bingodk 6 Reputation points
2021-10-20T16:33:38.823+00:00

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 Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,261 questions
Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,441 questions
{count} votes

2 answers

Sort by: Most helpful
  1. bingodk 6 Reputation points
    2021-10-27T13:16:14.987+00:00

    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, ...]

    1 person found this answer helpful.

  2. bingodk 6 Reputation points
    2021-10-26T13:58:07.83+00:00

    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.

    0 comments No comments