vmalloc/mongomock — pull request #31 by scottsexton (2013-06-27 04:34:46+00:00)
Title: Add Map Reduce

Hi vmalloc,

We've been using mongomock for a bit now at Threadless in our tests and it's awesome. But since we have a few map-reduce requirements too, I mocked out our fork of the source to support it. Thought it would be nice to contribute it back to the community.

NOTE: MongoDB map-reduce uses bson Code objects which aren't supported in pymongo until the python 2.7 version. Also, since mongodb runs javascript code to perform map-reduce, this introduces a dependency on pyexecjs, which again requires python 2.7. I updated the __version__ file to flag this, since this is a new feature and we'd lose python 2.6 support if you merge this. Python 3 support is still there.

There are full tests here to cover map_reduce, inline_map_reduce, map_reduce with queries and limits and map reduce using a bson SON object to save the output to another database. To support some of that, there are also additions to the Collection and Database classes to make them aware of their own names and return a string in the same format your code would expect from pymongo.