I need to utilize MongoDB's aggregation framework using ReactiveMongo. I only find this example which uses BSON. I would like to use JSON so I changed the code to :
def populatedStates(col: JSONCollection) = {
import col.BatchCommands.AggregationFramework.{AggregationResult, Group, Match, SumField}
val res: Future[AggregationResult] = col.aggregate(
Group(JsString("$state"))("totalPop" -> SumField("population")),
List(Match(JSONDocument("totalPop" -> JSONDocument("$gte" -> 10000000L)))))
res.map(_.firstBatch)
}
But there's no "JSONDocument" type.
What would be the correct way to finish this approach?
JSONDocument
is the same asJsObject
when you useJSONSerializationPack
.JsObject
converts toJSONDocument
with implicit writer.For example you want execute example from https://docs.mongodb.com/v3.4/reference/operator/aggregation/subtract/#subtract-numbers with 'total' sorting Using play reacitve mongo 0.12.0 it should look as