mongodbscalareactivemongo

ReactiveMongo aggregate count function


I'm trying to perform a ReactiveMongo aggregate call
Input: x of type X, y of type Y, list of types Z ( z : Z*)
Output: need to count all the records at mongodb such that: X field = x, Y field = y, and Z field in the list of types Z, how can i aggregate that?
Code Example:

collection.count(Some(Json.obj(
      X -> x,
      Y -> y,
      Z -> (Need to contain one of the Z Elements)
    ))

Thanks!


Solution

  • You may consider using $in aggregation

    collection.count(Some(Json.obj(
      X -> x,
      Y -> y,
      Z -> Json.obj("$in" -> YOUR_LIST)
    ))