I'm interested in community input, as I'm finally finishing adding support to Casbah's Query DSL for MongoDB Aggregation.
The trick is to try to prevent accidental usage of the aggregation syntax for queries, and check statements as cleanly as possible.
There are a few ways to go about this, and some concerns with each. My current favorite looks a bit like this:
(scroll over to see the whole thing)
val agg = | $group { ("lastAuthor" $last "$author") ++ ("firstAuthor" $first "$author") ++ ("_id" -> "$foo") } $unwind "$tags" $sort ( "foo" -> 1, "bar" -> -1 ) $skip 5 $limit 10 $match { "score" $gt 50 $lte 90 }