-
-
Save avevlad/af4f7b0aa8079db919f9 to your computer and use it in GitHub Desktop.
ReactiveMongo aggregation pipeline example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private def query( ): Future[ List[ JsObject ] ] = { | |
val group: Group = Group( BSONString( "$order.year" ) )( ("total", SumField( "value" )) ) | |
val pipeline: Seq[ PipelineOperator ] = Seq( group ) | |
val command: Future[ Stream[ BSONDocument ] ] = db.command( Aggregate( "opportunities", pipeline ) ) | |
command map { | |
c => | |
c.toList map { | |
d => | |
toJSON( d ).asInstanceOf[ JsObject ] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment