Skip to content

[2.4.x] Write $merge's keepExisting as the server spells it - #4594

Open
evanchooly wants to merge 1 commit into
2.4.xfrom
backport-merge-keep-existing-2.4
Open

evanchooly wants to merge 1 commit into
2.4.xfrom
backport-merge-keep-existing-2.4

Conversation

@evanchooly

Copy link
Copy Markdown
Member

Backport of #4591 to 2.4.x.

Problem: MergeCodec lower-cased the driver's enum names, so merge(...).whenMatched(WhenMatched.KEEP_EXISTING) was sent as whenMatched: "keep_existing". The server rejects that with BadValue: Enumeration value 'keep_existing' for field 'whenMatched' is not a valid value, so $merge with keepExisting could not be used from Morphia at all. The single-word values (replace, merge, fail, insert, discard) were unaffected.

Fix: the codec writes the camel-case MQL value (keepExisting).

Test: TestMerge.keepExisting merges two source documents into a target that already holds one of them, and checks that the existing document is kept and the other inserted. It fails with the BadValue error above without the codec change and passes with it.

Note: the cherry-pick conflicted only in the test, since 2.4.x still uses the TestNG AggregationTest style; the test was rewritten in that style. 2.4.x has no Critter mapper, so the test ran under reflection only.

Self-reviewed only.

MergeCodec lower-cased the driver's enum names, so WhenMatched.KEEP_EXISTING
became "keep_existing", which the server rejects. Write the camel-case MQL
value instead.

# Conflicts:
#	core/src/test/java/dev/morphia/test/aggregation/stages/TestMerge.java

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant