Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

umarhussain15
Copy link
Contributor

@umarhussain15 umarhussain15 commented Apr 6, 2024

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 between updateOne and updateMany, 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

  • Pull Request title starts with Apache NiFi Jira issue number, such as NIFI-00000
  • Pull Request commit message starts with Apache NiFi Jira issue number, as such NIFI-00000

Pull Request Formatting

  • Pull Request based on current revision of the main branch
  • Pull Request refers to a feature branch with one commit containing changes

Verification

Please indicate the verification steps performed prior to pull request creation.

Build

  • Build completed using mvn clean install -P contrib-check
    • JDK 21

Licensing

  • New dependencies are compatible with the Apache License 2.0 according to the License Policy
  • New dependencies are documented in applicable LICENSE and NOTICE files

Documentation

  • Documentation formatting appears as expected in rendered files

_relationships.add(REL_SUCCESS);
_relationships.add(REL_FAILURE);
relationships = Collections.unmodifiableSet(_relationships);
relationships = Set.of(REL_SUCCESS, REL_FAILURE);
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.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())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.allowableValues(MongoUpdateOption.allowedValues())
.allowableValues(MongoUpdateOption.class)

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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
String id = upsertedId.isString()? upsertedId.asString().getValue(): upsertedId.asObjectId().getValue().toString();
String id = upsertedId.isString() ? upsertedId.asString().getValue() : upsertedId.asObjectId().getValue().toString();

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>
@umarhussain15 umarhussain15 force-pushed the NIFI-12224-PutMongo-Add-support-for-updateMany-operation-with-operators-enabled-option branch from 96fc996 to 98179f7 Compare May 12, 2024 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants