Aggregation framework support?

9 views
Skip to first unread message

Sean Corfield

unread,
Sep 12, 2012, 3:08:58 PM9/12/12
to congomongo-dev
At World Singles, we're starting to look at MongoDB 2.2 and the
aggregation framework and obviously I'd like support for that in
CongoMongo...

The 2.9.x Java driver adds some helper APIs for that so it seems the
first step is to upgrade to 2.9.1 (done).

Has anyone had a look at the aggregation stuff yet? Any thoughts on
what CongoMongo might need to add to provide reasonable support for
this?
--
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/

"Perfection is the enemy of the good."
-- Gustave Flaubert, French realist novelist (1821-1880)

Sean Corfield

unread,
Sep 12, 2012, 3:50:38 PM9/12/12
to congomongo-dev
On Wed, Sep 12, 2012 at 12:08 PM, Sean Corfield <seanco...@gmail.com> wrote:
> Has anyone had a look at the aggregation stuff yet? Any thoughts on
> what CongoMongo might need to add to provide reasonable support for
> this?

To answer my own question, it looks like we just need one new
function, aggregate, that looks something like this:

(aggregate :coll op & ops)
;; e.g., (aggregate :foo {:$match {:type "airfare"}} {:$project
{:department 1, :amount 1}} {:$group {:_id "$department" :average
{:$avg "$amount"}}})

(based on http://www.mongodb.org/display/DOCS/Using+The+Aggregation+Framework+with+The+Java+Driver
)

It would call (.aggregate (get-coll :coll) (coerce op [from :mongo])
(into-array DBObject (map #(coerce % [from :mongo]) ops)))

That would return an AggregationOutput on which we'd call
.getCommandResult and then coerce that [:mongo to] to get the result.

I'll get a version of that knocked out today or tomorrow so folks can
play with it in a snapshot...

Sean Corfield

unread,
Sep 12, 2012, 4:19:32 PM9/12/12
to congomongo-dev
On Wed, Sep 12, 2012 at 12:50 PM, Sean Corfield <seanco...@gmail.com> wrote:
> I'll get a version of that knocked out today or tomorrow so folks can
> play with it in a snapshot...

It's in the latest 0.1.11-SNAPSHOT on Clojars if folks want to play with it.

I suspect we can make it easier to use by providing some helpers to
construct the aggregation operations ($match, $project, $group) and
I'd be interested in feedback on making the result more usable (it's
currently a CommandResult map with a :result key for the actual
computation result).
Reply all
Reply to author
Forward
0 new messages