zenexity/ReactiveMongo — pull request #27 by gatorcse (2013-01-16 04:28:43+00:00)
Title: Aggregation Framework

Idea for implementing the aggregation framework (#18) as a database command. Basic DSL contains operators used in the aggregation framework, allows aggregation queries to be written in Scala. Returns a regular BSONValue, to be parsed by json parsing library of choice. Each operator can create the BSON version of itself, can they are composed together to form the whole query. Example:
```scala
val command = Aggregate("content", Seq(
Project("keywords.text"),
Unwind("keywords"),
GroupField("keywords.text")("cnt" -> SumValue(1)),
Match(BSONDocument("cnt" -> BSONDocument("$gte" -> BSONInteger(6000))))
))
```
will produce:
```javascript
db.content.aggregate(
{$project:{"keywords.text":1}},
{$unwind:"$keywords"},
{$group:{_id:"$keywords.text", cnt:{$sum:1}}},
{$match:{"cnt":{$gt:1}}},
{$sort:{"cnt":1}}
)
```
Open to suggestions on how to make the argument to the "Match" command suck less. Would probably require implementing most of the other database operators. Actually, if this method is accepted, my next project will probably be to implement all of the operators specified on [MongoDB's operator page](http://docs.mongodb.org/manual/reference/operator/) and use marker traits to organize them into groups (typeclasses??) specifying where they can and cannot be used (numeric comparator, aggregation operation, projection, etc.)