Search code examples
mongodbcriteriahibernate-criteria

Criteria query throwing limitations error with multiple orOperator


I am trying to query with multiple orOperator using Criteria.orOperator.But it is throwing some limitations error that we cant use or operator twice.

Here is the query

    Criteria criteria1 = new Criteria();
    criteria1.orOperator(Criteria.where("dumEmployeeId").is(user.getId()),Criteria.where("toDumEmployeeId").is(user.getId())).andOperator(
    criteria1.orOperator(Criteria.where("priority").is("Important"),Criteria.where("priority").is("Urgent")));

Here two conditions is compulsory.There are two fields.And in both fields i need to check with two different data.Thats why i am having orOperator for individual fields.And then i am appending these two fields with and operator.But it is throwing limitations error.Can anyone tell how can i achieve this?


Solution

  • Try with below code.

    Criteria criteria1 = new Criteria();
                criteria1.orOperator(
                        Criteria.where("dumEmployeeId").is(user.getId()),
                        Criteria.where("toDumEmployeeId").is(user.getId())).
                        andOperator(
                            new Criteria().orOperator(
                                    Criteria.where("priority").is("Important"),
                                    Criteria.where("priority").is("Urgent")
                            )
                        );