Skip to content

Instantly share code, notes, and snippets.

@yujikiriki
Created September 18, 2014 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save yujikiriki/106c8c6c5e18100ae876 to your computer and use it in GitHub Desktop.
Save yujikiriki/106c8c6c5e18100ae876 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 ]
}
}
}
@scalastic
Copy link

I'm interesting by your example but where come from Aggregate and toJSON ?
Thanks for your reply !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment