We are running two copies of a django-based application within an Apache instance. We have this python code when loading an obje开发者_开发知识库ct from the database:
id = pymongo.objectid.ObjectId(hex_string)
d = self.collection.find_one({ '_id': id })
assert id == d['_id']
On one of the two applications (whichever we hit second) the assert fails. We've looked at the ids, and they are the same. Plus, when we change it to:
assert str(id) == str(d['_id'])
The assert passes. On our development machines (Win 7 64-bit, django dev server instead of Apache) this seems to work fine.
Stack: Ubuntu 10.04 LTS, Apache 2.2.14, Python 2.6.5, MongoDB 2.0, Pymongo 2.0.1
Update: We ran into another problem like this. We actually started referring to the objects as BSON object ids, and that fixed the second problem. However, the problem in this question is still occurring, even with using BSON object ids.
Kind of a shot in the dark, but you aren't using sharding by any chance, are you? I haven't tested it, but it seems like there is a possibility of having two docs with the same _id if you shard on a non-_id field. Are you generating the _id values yourself or letting pymongo do it for you on insert?
精彩评论