Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-1247

comparing ObjectId equality fails in map_reduce

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.5.4
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:
      pymongo 1.6, MongoDB 1.4.3. Single server, Ubuntu 9.10.
    • ALL

      I had a case where I wanted to compare ObjectId instances as part of a map_reduce and it was failing because checking for equality on two ObjectId instances that should have been the same aren't detected as being the same.

      Sample Python program (showing nothing was emit()'ed from map function, even though there should have been:
      import pymongo

      MAP = """
      function() {
      for (i=0; i < this.all.length; i++) {
      if (this.single == this.all[i])

      { emit(this._id, 1); }

      }
      }"""
      RED = "function(k,v)

      { return 1; }

      "

      dbc=pymongo.Connection(); db=dbc.test

      oids = []

      c1 = db.entries_with_ids
      c1.remove()
      oids.append(c1.save(

      {'x':1}

      ))
      oids.append(c1.save(

      {'x':2}

      ))

      c2 = db.mr_test
      c2.remove()
      c2.save(

      {'single':oids[0], 'all':oids}

      )

      c3 = c2.map_reduce(pymongo.code.Code(MAP), pymongo.code.Code(RED))

      print c2.find_one()
      print 'result size',c3.count()


      Sample output:

      {u'single': ObjectId('4c1a478603eba73620000000'), u'_id': ObjectId('4c1a478603eba73620000002'), u'all': [ObjectId('4c1a478603eba73620000000'), ObjectId('4c1a478603eba73620000001')]}

      result size 0

            Assignee:
            eliot Eliot Horowitz (Inactive)
            Reporter:
            shearic Richard Shea
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: