-1

I am using mule's MongoDB connector to update a document. The element that I am trying to update in this document is a object as shown below, its part of the full document i need just update two field by id.

{ "_id" : { "$oid": "61aa5bba4b5db6001c7aa333" },  "boQuantity" : 1, "ipQuantity": 1 }

Here is the flow doing the update

<mongo:update-documents doc:name="Update documents" doc:id="01d91a66-6b4f-464f-bac8-47fba99103de" config-ref="MongoDB" collectionName="test">
        <mongo:content-to-update ><![CDATA[#[{ "_id" : { "\$oid": "61aa5bba4b5db6001c7aa333" },  "boQuantity" : 1, "ipQuantity": 1 }]]]></mongo:content-to-update>
</mongo:update-documents>

when i debug the connector this show a error like wrong request:

"org.bson.json.JsonParseException: Invalid JSON input. Position: 1. Character: '�'."

I try to put the same json in query or content-to-update to i showed and nothing, maybe i'm use this component bad.

Any suggestions re: how to resolve this issue?

1 Answers1

0

The problem seems that the MongoDB connector expects a JSON content, but the expression used doesn't set the output type. It is probably being automatically assumed as Java by the context, causing the error.

To set the output correctly you can set the payload with a Transform component before the <mongo:update-documents> operation and use the following DataWeave script inside it:

%dw 2.0
output application/json
---
{
 "_id" : { "\$oid": "61aa5bba4b5db6001c7aa333" },  
 "boQuantity" : 1,
 "ipQuantity": 1 
}

Then remove the <mongo:content-to-update> element since the default content is the payload, and it will be set by the Transform component.

aled
  • 21,330
  • 3
  • 27
  • 34