title: pymongo mapreduce db assertion failure
body: <p>I'm just getting started with mongo and map/reduce, and I'm coming into the following error when using pymongo that I don't get when using the mongo command line directly (I realize there is a similar question to this one, but mine seems far more basic).</p>
  
  <p>I'm using the example directly from the pymongo documentation: <a href="http://api.mongodb.org/python/1.3%2B/examples/map_reduce.html" rel="nofollow">http://api.mongodb.org/python/1.3%2B/examples/map_reduce.html</a></p>
  
  <pre><code>from pymongo import Connection
  from pymongo.code import Code
  
  db = Connection().map_reduce_example
  db.things.insert({"x": 1, "tags": ["dog", "cat"]})
  db.things.insert({"x": 2, "tags": ["cat"]})
  db.things.insert({"x": 3, "tags": ["mouse", "cat", "dog"]})
  db.things.insert({"x": 4, "tags": []})
  
  
  m = Code("function () {this.tags.forEach(function(z) {emit('d, 1);});}")
  m = Code("function () {emit('dog', 1);}")
  
  r = Code("function (key, values) {var total = 0;for (var i = 0; i &lt; values.length; i++) {total += values[i];}return total;}")
  
  
  result = db.things.map_reduce(m, r)
  </code></pre>
  
  <p>This gives me the following error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "demo.py", line 17, in &lt;module&gt;
      result = db.things.map_reduce(m, r)
    File "/usr/local/lib/python2.6/dist-packages/pymongo-1.9-py2.6-linux-i686.egg/pymongo/collection.py", line 943, in map_reduce
      map=map, reduce=reduce, **kwargs)
    File "/usr/local/lib/python2.6/dist-packages/pymongo-1.9-py2.6-linux-i686.egg/pymongo/database.py", line 293, in command
      msg, allowable_errors)
    File "/usr/local/lib/python2.6/dist-packages/pymongo-1.9-py2.6-linux-i686.egg/pymongo/helpers.py", line 119, in _check_command_response
      raise OperationFailure(msg % response["errmsg"])
  pymongo.errors.OperationFailure: command SON([('mapreduce', u'things'), ('map', Code("function () {emit('dog', 1);}", {})), ('reduce', Code('function (key, values) {var total = 0;for (var i = 0; i &lt; values.length; i++) {total += values[i];}return total;}', {}))]) failed: db assertion failure
  </code></pre>
  
  <p>However, defining the map/reduce functions in mongo and running the following command works:</p>
  
  <pre><code>db.things.mapReduce(mm,r,{out:{inline:1}})
  </code></pre>
  
  <p>The defining difference seems to be the {out:{inline:1}} option. Is there a way to get that into the call in pymongo?</p>
  
  <p>Thanks,</p>
  
  <p>Adam.</p>