Two things:

1. You need to use valid JSON. Your query is not a valid JSON example
because some of the values are not quoted.
2. You need to make sure the update option is set to use operators, not use
document.

Let us know if that helps.

Mike

On Thu, Jun 21, 2018 at 3:19 PM Ryan Hendrickson <
[email protected]> wrote:

> Hi,
>    I can't seem to figure out the right combo of parameters to get a
> document to update in Mongo using the PutMongo processor and the $set
> operator.
>
> Try 1:
> The incoming flowfile contains the customId: abc
>
> NiFi Processor Properties:
>    Mode: update
>    Upsert: false
>    Update Query Key: No value set
>    Update Query: {"customId":{$customId}},{$set: {"status":"Stage_2"}}
>    Update Mode: With operators enabled
>
> This consistently fails, the abbreviated log output:
> PutMongo Failed to insert into MongoDB due to
> com.mongodb.util.JSONParseException:
> abc
> ...
> at com.mongodb.util.JSONParser.parse(JSON.java:230)
> ...
> at org.apache.nifi.processors.mongodb.PutMongo.onTrigger(PutMongo.java:201)
>
>
> https://github.com/apache/nifi/blob/rel/nifi-1.6.0/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/PutMongo.java#L201
>
> It looks like it's trying to parse the incoming flowfile as a JSON
> document with the above parameters set.
>
> Try 2:
> With that in mind, I changed my input flowfile to be a json object, but I
> don't think it should need to be, because I'm using the Update Query with
> Operators.
> New incoming flow file: {"customId":"abc"}
>
> This allows it to get line 225, before it fails with:
> PutMongo Failed to insert into MongoDB due to
> java.lang.IllegalArgumentException: Invalid BSON field name customId:
> at org.bson.AbstractBsonWriter.writeName(AbstractBsonWriter.java:494)
> at org.apache.nifi.processors.mongodb.PutMongo.onTrigger(PutMongo:225)
>
>
> https://github.com/apache/nifi/blob/rel/nifi-1.6.0/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/PutMongo.java#L225
>
> Line 225: //collection.updateOne(query, update, new
> UpdateOptions().upsert(upsert));
>    query = {"customId":{$customId}},{$set: {"status":"Stage_2"}}
>    update = {"customId":"abc"}
> It looks like the 'update' variable, is my incoming flowfile.  I'm not
> sure why it would be, based on my understanding of the processor properties
> works.
>
> If anyone has any insight on how to set this up for using the operators to
> update a document, I'd really appreciate the insight.  I'm lost in
> debugging.
>
> Thanks,
> Best,
> Ryan
>
>

Reply via email to