Which limitations of the org.bson.Document do not allow multiple $or / $and expressions?
Closed this issue · 2 comments
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"}]}
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, 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
?