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

Which limitations of the org.bson.Document do not allow multiple $or / $and expressions? #4832

Closed
hadjiski opened this issue Nov 10, 2024 · 2 comments
Labels
for: stackoverflow A question that's better suited to stackoverflow.com status: duplicate A duplicate of another issue

Comments

@hadjiski
Copy link

hadjiski commented Nov 10, 2024

org.springframework.data.mongodb.InvalidMongoDbApiUsageException: 
Due to limitations of the org.bson.Document, you can't add a second '$or' expression specified as '$or : 
[Document{{active=false}}, Document{{active=null}}]'; Criteria already contains '$or : 
[Document{{payerId=Document{{$in=[64aeae270d0313320626dc55]}}}}, 
Document{{payerLoginId=Document{{$in=[64aeae270d0313320626dc55]}}}}]'

For the famous above issue there is a well-known workaround, instead of:

criteria.orOperator(Criteria.where(field).is(value), Criteria.where(field).is(anotherValue));
criteria.orOperator(Criteria.where(field2).is(value2), Criteria.where(field2).is(anotherValue2));

To chain the multiple $or within an $and:

criteria.andOperator(
 new Criteria().orOperator(Criteria.where(field).is(value), Criteria.where(field).is(anotherValue)),
 new Criteria().orOperator(Criteria.where(field2).is(value2), Criteria.where(field2).is(anotherValue2)));

Though my question is what limitation are we workarounding here? The mongodb itself can work well with:

{$or:[{field:"value"}, {field:"anotherValue"}], $or:[{field2:"value2"}, {field2:"anotherValue2"}]}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 10, 2024
@christophstrobl
Copy link
Member

Thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. We prefer to use GitHub issues only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.

Nevertheless, The org.bson.Document is basically a Map structure. #4715 is somewhat close to this one.

@christophstrobl christophstrobl closed this as not planned Won't fix, can't repro, duplicate, stale Nov 11, 2024
@christophstrobl christophstrobl added for: stackoverflow A question that's better suited to stackoverflow.com status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged labels Nov 11, 2024
@hadjiski
Copy link
Author

hadjiski commented Nov 11, 2024

@christophstrobl, thanks for replying that promptly, I re-posted my question on Stack Overflow.
Though what about a straight request here for enhancing the spring data mongodb to remove this limitation and allow multiple $or/$and?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: stackoverflow A question that's better suited to stackoverflow.com status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

3 participants