Worth knowing: MongoDB Aggregation

I spent a little bit of time over the past few days finally upgrading our production Mongo instances for PubGears to the latest stable release.

One of the biggest advantages this gives us is all the new aggregation stuff that Mongo has to offer (which I’ve been using in a few other projects already as well).

If you don’t know about the Mongo aggregation stuff, I *highly* recommend you check it out ( http://docs.mongodb.org/manual/aggregation/ )

There are a bunch of really interesting and useful things this allows for, including simple things like grouping and counting on distinct items…you can see an example of that in action in the USV open source conversation project -> https://github.com/unionsquareventures/theconversation/blob/master/lib/tagsdb.py (this query returns the tags a given user has used, and the count of how many times for each)

..and if you use pymongo (like we are), then I also recommend you dig into the associated documentation a bit as well ( http://api.mongodb.org/python/current/examples/aggregation.html ).

At first glance a lot of this will probably look pretty complex and deep (at least it did to me), but once you grep it it’s a powerful set of features…so well worth the reading and required ‘grep’ time to understand.

This post has received 46 loves.


ARCHIVE OF POSTS



This is the personal blog of Kevin Marshall (a.k.a Falicon) where he often digs into side projects he's working on for digdownlabs.com and other random thoughts he's got on his mind.

Kevin has a day job as CTO of Veritonic and is spending nights & weekends hacking on Share Game Tape. You can also check out some of his open source code on GitHub or connect with him on Twitter @falicon or via email at kevin at falicon.com.

If you have comments, thoughts, or want to respond to something you see here I would encourage you to respond via a post on your own blog (and then let me know about the link via one of the routes mentioned above).