Support derived queries using the same field multiple times - #5243
Open
anjeongkyun wants to merge 2 commits into
Open
anjeongkyun wants to merge 2 commits into
anjeongkyun wants to merge 2 commits into
Conversation
A derived query that constrains one property twice, such as findByAgeGreaterThanAndAgeLessThan, failed because both conditions were written into a single document. Combine them with $and instead. Closes spring-projects#4715 Signed-off-by: anjeongkyun <anwjdrbs123@gmail.com>
Missed from the PR checklist. Signed-off-by: anjeongkyun <anwjdrbs123@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A derived query that constrains the same property twice fails today:
MongoQueryCreator#andsends every part throughbase.and(dotPath), so the second part onageis added to the same document and the chain cannot be rendered.This adds one branch there: when the property is already constrained in the current chain, the parts are combined with
$and.Queries without a repeated property keep their current single-document shape, and
$orbranches are unaffected, since each branch carries its own chain. Both are covered by tests.The
CriteriaAPI is not touched. Rejecting a duplicate key there was called intentional in #4715, so this stays on the derivation side;CriteriaUnitTestsandQueryTestspass unchanged.One thing worth flagging: with three parts on the same property the result is
{"$and": [A, B], "age": C}rather than a flat{"$and": [A, B, C]}. It is valid and all three conditions are kept, but I can flatten it if you would rather have the tidier shape.Tests run:
MongoQueryCreatorUnitTests(68), plusCriteriaUnitTests,CriteriaTests,QueryTests,QueryMapperUnitTests,PartTreeMongoQueryUnitTestsand the other query suites (388 total), and the AOT repository tests (183). The five new tests fail without the change.Closes #4715