pymongo mapreduce db assertion failure
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).

I'm using the example directly from the pymongo documentation: http://api.mongodb.org/python/1.3%2B/examples/map_reduce.html


    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 < values.length; i++) {total += values[i];}return total;}")
    
    
    result = db.things.map_reduce(m, r)

This gives me the following error:


    Traceback (most recent call last):
      File "demo.py", line 17, in <module>
        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 < values.length; i++) {total += values[i];}return total;}', {}))]) failed: db assertion failure


However, defining the map/reduce functions in mongo and running the following command works:


    db.things.mapReduce(mm,r,{out:{inline:1}})

The defining difference seems to be the <tt>{out:{inline:1}}</tt> option. Is there a way to get that into the call in pymongo?

Thanks,

Adam.
pymongo mapreduce db assertion failure
===

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).

I'm using the example directly from the pymongo documentation: http://api.mongodb.org/python/1.3%2B/examples/map_reduce.html


    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 < values.length; i++) {total += values[i];}return total;}")
    
    
    result = db.things.map_reduce(m, r)

This gives me the following error:


    Traceback (most recent call last):
      File "demo.py", line 17, in <module>
        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 < values.length; i++) {total += values[i];}return total;}', {}))]) failed: db assertion failure


However, defining the map/reduce functions in mongo and running the following command works:


    db.things.mapReduce(mm,r,{out:{inline:1}})

The defining difference seems to be the <tt>{out:{inline:1}}</tt> option. Is there a way to get that into the call in pymongo?

Thanks,

Adam.