play-reactivemongo

How to use ReactiveMongo + JSON aggregation framework in Play Framework?

谁说胖子不能爱 提交于 2019-12-02 09:54:04
问题 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

How to use ReactiveMongo + JSON aggregation framework in Play Framework?

*爱你&永不变心* 提交于 2019-12-02 06:23:54
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