[SERVER-1247] comparing ObjectId equality fails in map_reduce Created: 17/Jun/10  Updated: 12/Jul/16  Resolved: 23/Jun/10

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 1.5.4

Type: Bug Priority: Major - P3
Reporter: Richard Shea Assignee: Eliot Horowitz (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

pymongo 1.6, MongoDB 1.4.3. Single server, Ubuntu 9.10.


Operating System: ALL
Participants:

 Description   

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



 Comments   
Comment by Eliot Horowitz (Inactive) [ 23/Jun/10 ]

You can't overload == in js, but I did add a .equals method which should work.

Comment by auto [ 23/Jun/10 ]

Author:

{'login': 'erh', 'name': 'Eliot Horowitz', 'email': 'eliot@10gen.com'}

Message: ObejctId.equals SERVER-1247
http://github.com/mongodb/mongo/commit/1dc2b9cd17ecae64205ea6e8ad365def7848cdb0

Generated at Thu Feb 08 02:56:30 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.