Search code examples
javamongodb-queryquarkusquarkus-panache

how to query with an attribute that have different values in quarkus panache


I want to count all users that have status which is different from 'UNEMPLOYED';

My Collection looks like this:

  [   
  {
     "id" : "1",
     "name": "Mr.A",
     "status": "UNEMPLOYED"
  },
  {
     "id" : "2",
     "name": "Mr.B",
     "status": "WORKING"
  },
  { 
     "id" : "3",
     "name": "Mr.B",
     "status": "WORKING"
  },
  { 
     "id" : "4",
     "name": "Mr.D",
     "status": "STUDYING"
  }
  ] 

Here is my query:

User.count("{'userStatus': :userStatus}",
            Parameters.with("userStatus", UserStatus.STUDYING)
            .and("userStatus", UserStatus.WORKING)
           )

What I expect is the query should return 3 but It gives me 1 instead. Can you help me find out where is the wrong part ? Thanks a lot.


Solution

  • What you are doing is effectively setting userStatus to a single value.

    You likely want to do something like:

    User.count("where userStatus = ?1 or userStatus = ?2", UserStatus.STUDYING, UserStatus.WORKING)