spring-data-mongodb
spring-data-mongodb copied to clipboard
Add static method to create OR criterion.
Currently the only way to create an $or only query is counter intuitive and leads people to creating $and combined criterions to a single element $or as outlined below.
query(where("title").is(...).orOperator(where("content").is(...))
{
"title": ...,
"$or": [
{
"content": ...
}
]
}
The correct, rather cumbersome usage would be as follows:
query(new Criteria().orOperator(where("title").is(...), where("content").is(...)))
Introducing a static or(Critieria... criterions) method would allow for simpler usage
query(or(where("title").is(...), where("content").is(...)))
Is this still something we're interested in? If so, can you confirm if my following understanding of the design is correct?
- The Criteria class will have the static method of
orsimilar towhich. So, anywhere top level orOperator is needed, one can just doCriteria.or(... criterions) - Will this also need to deprecate the
new Criteria().orOperator(...)method? I don't we should do this, it's still useful in chaining with other criterion. - Does this also mean we should move
norOperator,andOperator? createCriteriaList()is an easy candidate to be made static as it does no side effect, butregisterCriteriaChainElement()doesn't seem to be needed anymore with this method, as this static method, so, doesn't have risk of causingunknown top level operatorerrors. This is a correct assumption, right?
Can you also let me know if someone is already looking into this?
related to #3895