New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NIFI-12224: Add support for updateMany operation with operators enabled option in PutMongo
processor
#8610
base: main
Are you sure you want to change the base?
Conversation
_relationships.add(REL_SUCCESS); | ||
_relationships.add(REL_FAILURE); | ||
relationships = Collections.unmodifiableSet(_relationships); | ||
relationships = Set.of(REL_SUCCESS, REL_FAILURE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this enhancement is meant to be back ported to the 1. x branch, then this should be reverted as Set.of
is not supported in Java 8.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a note on that, this is a helpful change for the main branch, and if the other aspects of the feature are to be backported, an alternative PR could be raised.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ticket description says that currently the behavior of the processor is not clearly documented (where it uses updateOne
and user might be expecting updateMany
), so I think it's a bug fix. For bug fixes, we usually do a backport as well? I will then raise another pull request for 1.x branch and keep these changes for main branch.
@@ -141,8 +135,8 @@ public class PutMongoRecord extends AbstractMongoProcessor { | |||
.displayName("Update Mode") | |||
.dependsOn(UPDATE_KEY_FIELDS) | |||
.description("Choose between updating a single document or multiple documents per incoming record.") | |||
.allowableValues(UPDATE_ONE, UPDATE_MANY, UPDATE_FF_ATTRIBUTE) | |||
.defaultValue(UPDATE_ONE.getValue()) | |||
.allowableValues(MongoUpdateOption.allowedValues()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.allowableValues(MongoUpdateOption.allowedValues()) | |
.allowableValues(MongoUpdateOption.class) |
.displayName("Mongo Update Query Mode") | ||
.dependsOn(UPDATE_OPERATION_MODE,UPDATE_WITH_OPERATORS) | ||
.description("Choose between 'updateOne' or 'updateMany' Mongo documents per incoming flow file.") | ||
.allowableValues(MongoUpdateOption.allowedValues()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.allowableValues(MongoUpdateOption.allowedValues()) | |
.allowableValues(MongoUpdateOption.class) |
...nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/PutMongoHelper.java
Outdated
Show resolved
Hide resolved
...undle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/PutMongo.java
Outdated
Show resolved
Hide resolved
...undle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/PutMongo.java
Outdated
Show resolved
Hide resolved
flowFile = session.putAttribute(flowFile, ATTRIBUTE_UPDATE_MODIFY_COUNT, String.valueOf(updateResult.getModifiedCount())); | ||
BsonValue upsertedId = updateResult.getUpsertedId(); | ||
if (upsertedId != null) { | ||
String id = upsertedId.isString()? upsertedId.asString().getValue(): upsertedId.asObjectId().getValue().toString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String id = upsertedId.isString()? upsertedId.asString().getValue(): upsertedId.asObjectId().getValue().toString(); | |
String id = upsertedId.isString() ? upsertedId.asString().getValue() : upsertedId.asObjectId().getValue().toString(); |
...undle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/PutMongo.java
Outdated
Show resolved
Hide resolved
...nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/PutMongoHelper.java
Outdated
Show resolved
Hide resolved
These changes will allow the processor to use Mongo updateMany operation in update mode. A different name for update mode property is used in PutMongo than PutMongoRecord since the property name "Update Mode" is already used in PutMongo Test cases for `PutMongo` updated to use Map and Document classes instead of string based json input. Signed-off-by: Umar Hussain <umarhussain.work@gmail.com>
96fc996
to
98179f7
Compare
These changes will allow the processor to use Mongo updateMany operation in update mode.
PutMongo processor was only doing
updateOne
in mongo operator mode. Now it has an additional configuration to select betweenupdateOne
andupdateMany
, which will help in clarifying the behavior of the processor to the user.A different name for update mode property is used in PutMongo than PutMongoRecord since the property name "Update Mode" is already used in PutMongo
Test cases for
PutMongo
updated to use Map and Document classes instead of string based json input.Summary
NIFI-12224
Tracking
Please complete the following tracking steps prior to pull request creation.
Issue Tracking
Pull Request Tracking
NIFI-00000
NIFI-00000
Pull Request Formatting
main
branchVerification
Please indicate the verification steps performed prior to pull request creation.
Build
mvn clean install -P contrib-check
Licensing
LICENSE
andNOTICE
filesDocumentation