Malte created NIFI-12224:
----------------------------
Summary: PutMongo with operator only updates the first match
Key: NIFI-12224
URL: https://issues.apache.org/jira/browse/NIFI-12224
Project: Apache NiFi
Issue Type: Bug
Components: Core Framework
Affects Versions: 1.23.2
Reporter: Malte
Problem to solve: In my case, I wanted to add a field to a couple of documents
that fullfill a certain condition. The [PutMongo
documentation|https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-mongodb-nar/1.23.0/org.apache.nifi.processors.mongodb.PutMongo/additionalDetails.html]
states that if you select the "With Operators Enabled" mode, then the "Update
Query" property can be used "to find one or more documents to update". But the
processor uses the ["updateOne" method of the MongoCollection
class|https://github.com/apache/nifi/blob/22ad7d542d627e767f962b13236da90a0d6410f5/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/PutMongo.java#L230C21-L230C41],
which will only update the first match.
Proposed solutions:
1. Update the documentation to correctly state that only one document (the
first match) can be updated using an operator.
2. Use the updateMany method of the MongoCollection class.
3. Add a property like ["update-mode" from
PutMongoRecord|https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-mongodb-nar/1.23.0/org.apache.nifi.processors.mongodb.PutMongoRecord/]
to switch between updateOne and updateMany.
Workaround: Right now I use the RunMongoAggregation and use a $match,
$addFields and $merge operation to achieve what I want. But I think the
PutMongo processor would be the intuitive way to go.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)