I'm accessing CosmosDB3.2 via MongoDB connector v5.3.1 in a Mule 4 api.
I've following collection in database:
{ "id": "range",
"from": 100,
"to": 1,
"used": 0
}
I will fetch data from this collection based upon id=range. However, same time I also want to update, and fetch the updated data - to support multiple simultaneous hits with correct data retrieval.
Search Query:
%dw 2.0
output application/json
---
{
"id" : "range"
}
Update Query:
%dw 2.0
output application/json
---
{ "\$inc": {
"from": -1,
"used": 1
}}
Hence, connector code becomes:
<mongo:find-one-and-update-document doc:name="Find one and update document" doc:id="f7fb0fe6-ae0c-4d82-8766-92d6e7081c0e" config-ref="MongoDB_Config" collectionName="test" returnNewDocument="true">
<mongo:find-query ><![CDATA[#[vars.findQuery]]]></mongo:find-query>
<mongo:content-to-update ><![CDATA[#[vars.updateQuery]]]></mongo:content-to-update>
</mongo:find-one-and-update-document>
Expected payload:
{
"id": "range",
"from": 99,
"to": 1,
"used": 1
}
However, I figured that "Find one and update document" connector is not able to accept update function "inc". It's giving following exception:
The dollar ($) prefixed field '$inc' in '$inc' is not valid for storage.
Has anyone faced similar issue and have any solution, please help. I think sequence support is not there in mongodb/cosmosdb.
Thanks, Swati Jain