Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avevlad/af4f7b0aa8079db919f9 to your computer and use it in GitHub Desktop.
Save avevlad/af4f7b0aa8079db919f9 to your computer and use it in GitHub Desktop.
ReactiveMongo aggregation pipeline example
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