0

I am trying to pass multiples value in $in query using Query DSL with Reactive Mongo Extensions. But the result is empty list. Follwoing is my Code:

def findUsersByRolesIds(rolesIds: List[BSONObjectID], page: Int, pageSize: Int): Future[List[User]] = {
  logger.info("findUsersByRolesIds Reactive Repository Method");

  userGenericRepo.find($doc("userRoles._id" $in (rolesIds)), $doc("createdOn" -> -1 ), page, pageSize);
}

When i am trying to execute above code, the result was empty.

But when i pass, below code the result was return.

def findUsersByRolesIds(rolesIds: List[BSONObjectID], page: Int, pageSize: Int): Future[List[User]] = {
  logger.info("findUsersByRolesIds Reactive Repository Method");

  userGenericRepo.find($doc("userRoles._id" $in (BSONObjectID.apply("5548b098b964e7039852ff58"))), $doc("createdOn" -> -1 ), page, pageSize);
}

The main problem is that, i have multiple value, so that's why i create the list but here the list is not working. How this query is possible with reactive mongo extenstions and Query DSL.

Harmeet Singh Taara
  • 6,483
  • 20
  • 73
  • 126
  • Try `val query = $doc(...); println(s"query = ${BDONDocument pretty query}")` and then execute the query manually from the MongoDB CLI to check data are there. – cchantep May 06 '15 at 17:27
  • @cchantep this is the output of query `query = {"userRoles._id":{"$in":[[{"$oid":"5548b098b964e7039852ff58"}]]}}`. still there is no data return. – Harmeet Singh Taara May 07 '15 at 06:05

1 Answers1

2

$in expects varargs, ie val dsl: BSONDocument = "age" $in (1, 2, 3). So you cannot directly pass a collection to it. Try using this "age" $in (rolesIds: _*).

fcs
  • 926
  • 1
  • 8
  • 14