title: 'Collection' object is not callable. If you meant to call the 'mapReduce' method on a 'Collection' object it is failing because no such method exists
body: <p>I'm using pyMongo 1.11 and MongoDB 1.8.2. I'm trying to do a fairly complex Map/Reduce. I prototyped the functions in Mongo and got it working, but when I tried transferring it to Python, I get:</p>
  
  <pre><code>---------------------------------------------------------------------------
  TypeError                                 Traceback (most recent call last)
  /Developer/R-and-D/&lt;ipython-input-71-3c3a43221538&gt; in &lt;module&gt;()
  ----&gt; 1 results = db.user_actions.mapReduce(map, reduce, "user_entities_interactions")
  
  /Library/Python/2.7/site-packages/pymongo/collection.pyc in __call__(self, *args, **kwargs)
     1099                         "call the '%s' method on a 'Collection' object it is "
     1100                         "failing because no such method exists." %
  -&gt; 1101                         self.__name.split(".")[-1])
  
  TypeError: 'Collection' object is not callable. If you meant to call the 'mapReduce' method on a 'Collection' object it is failing because no such method exists.
  </code></pre>
  
  <p>My collection looks like this:</p>
  
  <pre><code>{ "_id" : ObjectId("..."), "entity_id" : 1556, "user_id" : 466112 }
  { "_id" : ObjectId("..."), "entity_id" : 1366, "user_id" : 10057 }
  { "_id" : ObjectId("..."), "entity_id" : 234, "user_id" : 43650 }
  { "_id" : ObjectId("..."), "entity_id" : 6, "user_id" : 34430 }
  { "_id" : ObjectId("..."), "entity_id" : 461, "user_id" : 3416 }
  { "_id" : ObjectId("..."), "entity_id" : 994, "user_id" : 10057 }
  { "_id" : ObjectId("..."), "entity_id" : 296, "user_id" : 466112 }
  </code></pre>
  
  <p>The code I'm running in Python is:</p>
  
  <pre><code>map = Code("""function () {
          emit(this.user_id, { 
              user_id : this.user_id,
              entity_id : this.entity_id});
      }""")
  
  reduce = Code("""function (key, values) {
          var entities = { user_id : values[0].user_id, entity_id : [ ] };
          for (var i = 0; i &lt; values.length; i++) {
              entities.entity_id[i] = values[i].entity_id;
          }
          return entities;
      }""")
  results = db.user_actions.mapReduce(map, reduce, "user_entities_interactions")
  </code></pre>
  
  <p>What the result <em>should</em> look like is:</p>
  
  <pre><code>{ "_id" : 3416, "value" : { "user_id" : 3416, "entity_id" : 461 } }
  { "_id" : 10057, "value" : { "user_id" : 10057, "entity_id" : [ 1366, 994 ] } }
  { "_id" : 34430, "value" : { "user_id" : 34430, "entity_id" : 6 } }
  { "_id" : 43650, "value" : { "user_id" : 43650, "entity_id" : 234 } }
  { "_id" : 466112, "value" : { "user_id" : 466112, "entity_id" : [ 1556, 296 ] } }
  </code></pre>
  
  <p>I'm not clear on what the problem is. The error says that the 'Collection' object has no mapReduce method, but that's clearly not true as the example at <a href="http://api.mongodb.org/python/current/examples/map_reduce.html" rel="noreferrer">http://api.mongodb.org/python/current/examples/map_reduce.html</a> works and what is 'things' if  not a collection?</p>
  
  <p>Also, in case you're wondering why I'm not doing this with group() it's because I have <strong>more than 20000 unique keys</strong>.</p>