spring-data-mongodb icon indicating copy to clipboard operation
spring-data-mongodb copied to clipboard

Add static method to create OR criterion.

Open christophstrobl opened this issue 4 years ago • 1 comments

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(...)))

christophstrobl avatar Nov 16 '21 10:11 christophstrobl

Is this still something we're interested in? If so, can you confirm if my following understanding of the design is correct?

  1. The Criteria class will have the static method of or similar to which. So, anywhere top level orOperator is needed, one can just do Criteria.or(... criterions)
  2. 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.
  3. Does this also mean we should move norOperator, andOperator?
  4. createCriteriaList() is an easy candidate to be made static as it does no side effect, but registerCriteriaChainElement() doesn't seem to be needed anymore with this method, as this static method, so, doesn't have risk of causing unknown top level operator errors. This is a correct assumption, right?

Can you also let me know if someone is already looking into this?

thekaleidoscope avatar May 15 '22 14:05 thekaleidoscope

related to #3895

christophstrobl avatar Mar 07 '23 08:03 christophstrobl