-
Type:
Bug
-
Resolution: Cannot Reproduce
-
Priority:
Major - P3
-
None
-
Affects Version/s: 1.4.3
-
Component/s: None
-
None
-
Environment:OS: CentOS_5.4_x64_v4.4 [rev 4]
Architecture: x86_64
MongoDB: 1.4.3
-
ALL
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Have a strange mongoDB behavior, looks like a bug: find() and count() works sometimes incorrect for "$type" requests (both in mongo shell and pymongo).
Problem found after fixing values from float to integer via Python script for col collection in fields parent.ancestors ( "parent" is array, "ancestors" is array.)
Python fixing script had run on all fields found by request:
db.col.find( { 'parent.ancestors':
})
Change was done by several means:
1) partial change
- update(
{"_id":..}
{"$unset": ...}
)
- update(
{"_id":..}
{"$set": ...}
)
2) change the whole entry (del and then assigning with int(value) for each) and saving the complete entry back with pymongo col.save(item)
A great number of values was changed (ok), but, after fix was complete, the mongoDB still reported 3232 non-integers('$type': 1) for this field.
Meantime, if any of reported non-integer entries is inspected with its _id, then mongoDB reports that the field is integer!!! (Expected result: mongo should report those values as non-integers OR it should not include those values into results of non-integer search)
> //state before fix to integers
> db.col.find( { 'parent.ancestors': {'$type': 1} }).count()
640876
> //state after fix to integers
> db.col.find( { 'parent.ancestors': {'$type': 1} }).count()
3232
> db.col.find( { 'parent.ancestors': {'$type': 1} },{_id:1})
{ "_id" : ObjectId("4c3dd581b1833907a5000063") }
{ "_id" : ObjectId("4c402159b183392f5300c2dc") }
{ "_id" : ObjectId("4c3f724bb1833929b700fa1b") }
{ "_id" : ObjectId("4c401edab183392f5300b29a") }
{ "_id" : ObjectId("4c3f8cddb1833929b703149e") }
{ "_id" : ObjectId("4c3f38adb18339113203e518") }
{ "_id" : ObjectId("4c401a7eb183392f53008b69") }
{ "_id" : ObjectId("4c3f2b7bb183391132038592") }
{ "_id" : ObjectId("4c3f15afb183391132029d9d") }
{ "_id" : ObjectId("4c3f85dab1833929b7028749") }
{ "_id" : ObjectId("4c402fd1b183392f53012c1a") }
{ "_id" : ObjectId("4c40818cb183392f5302bdb8") }
{ "_id" : ObjectId("4c3f0e95b183391132022e04") }
{ "_id" : ObjectId("4c37e069b183393d030136c8") }
{ "_id" : ObjectId("4c3889ceb183393d03023dd4") }
{ "_id" : ObjectId("4c3acafab183393d0304c686") }
{ "_id" : ObjectId("4c3daccbb18339144e00004a") }
{ "_id" : ObjectId("4c3df945b1833907a500758b") }
{ "_id" : ObjectId("4c3ee4d9b18339113200ad43") }
{ "_id" : ObjectId("4c3ef11fb183391132011718") }
has more
> db.col.find( { 'parent.ancestors': {'$type': 1}, '_id': ObjectId("4c3f0e95b183391132022e04") }).count()
0
> db.col.find( {"_id": ObjectId("4c3dd581b1833907a5000063"), "parent.ancestors": {"$type": 1} }).count()
0
> // TESTING EACH VALUE of array:
> db.col.find( {"_id": ObjectId("4c3dd581b1833907a5000063")},{parent:1})
{ "_id" : ObjectId("4c3dd581b1833907a5000063"), "parent" : [
{
"collection" : "col",
"ancestors" : [
68397,
68400,
309252,
309305,
309365,
309440,
309486,
309506,
309573,
309623
],
"parentGroupId" : 309623
}
] }
>
> db.col.find( { "parent.0.ancestors.0": {"$type": 16}, "_id": ObjectId("4c3dd581b1833907a5000063") },{parent:1}).count()
1
> db.col.find( { "parent.0.ancestors.2": {"$type": 16}, "_id": ObjectId("4c3dd581b1833907a5000063") },{parent:1}).count()
1
> db.col.find( { "parent.0.ancestors.3": {"$type": 16}, "_id": ObjectId("4c3dd581b1833907a5000063") },{parent:1}).count()
1
> db.col.find( { "parent.0.ancestors.4": {"$type": 16}, "_id": ObjectId("4c3dd581b1833907a5000063") },{parent:1}).count()
1
> db.col.find( { "parent.0.ancestors.5": {"$type": 16}, "_id": ObjectId("4c3dd581b1833907a5000063") },{parent:1}).count()
1
> db.col.find( { "parent.0.ancestors.6": {"$type": 16}, "_id": ObjectId("4c3dd581b1833907a5000063") },{parent:1}).count()
1
> db.col.find( { "parent.0.ancestors.6": {"$type": 1}, "_id": ObjectId("4c3dd581b1833907a5000063") },{parent:1}).count()
0
> db.col.find( { "parent.0.ancestors.7": {"$type": 16}, "_id": ObjectId("4c3dd581b1833907a5000063") },{parent:1}).count()
1
> db.col.find( { "parent.0.ancestors.8": {"$type": 16}, "_id": ObjectId("4c3dd581b1833907a5000063") },{parent:1}).count()
1
> db.col.find( { "parent.0.ancestors.9": {"$type": 16}, "_id": ObjectId("4c3dd581b1833907a5000063") },{parent:1}).count()
1
Thus, it looks like find() and count() works sometimes incorrect for "$type" requests (both in mongo shell and pymongo).