-
Type: Bug
-
Resolution: Gone away
-
Priority: Major - P3
-
None
-
Affects Version/s: 2.0.0
-
Component/s: MapReduce
-
Environment:Pymongo 2.0.1/OS X
-
Query Optimization
-
ALL
Re-using the same variable in the scope option to two different CodeWScope objects (bson.code.Code, with scope keyword arg) results in the scope from reduce "leaking" into the scope of map.
I've read the Python code, and I don't believe this is due to a bug in Pymongo.
Short Python script to reproduce:
from bson.code import Code import pymongo conn = pymongo.Connection() db = conn.test db.foo.drop() db.foo.save({'a': 1}) db.foo.save({'a': 1}) db.foo.save({'a': 2}) db.foo.save({'a': 2}) map = Code( """ function() { emit( this.a, {one: scopevar, two: 0} ); } """, scope={'scopevar': 1} ) reduce = Code( """ function(key, values) { var out = {one: 0, two: 0}; for (var i=0; i<values.length; i++) { out.one += values[i].one; out.two += scopevar; } return out; }""", scope={'scopevar': 2} ) # should give in 2 results, each with # field "one" == 2, and field "two" == 4 for result in db.foo.inline_map_reduce(map, reduce): print result
Actual results:
{u'_id': 1.0, u'value': {u'two': 4.0, u'one': 4.0}} {u'_id': 2.0, u'value': {u'two': 4.0, u'one': 4.0}}