-
Type:
Bug
-
Resolution: Done
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
Environment:mongodb 2.4.8
-
ALL
If I use $lt and $gt on the same variable twice in a find() call, it only uses the last one.
This is a problem because we should use all information in a find() call.
Steps to reproduce
------------------------
> db.scores.drop()
> score_types = ["exam", "homework", "quiz"]
[ "exam", "homework", "quiz" ]
> for ( i = 1 ; i <= 100 ; i++ ) { for ( j = 0 ; j <= 2 ; j++ ) { db.scores.insert(
) } }
You now have 300 documents in the 'scores' collection, with 'score' values ranging from 1-100, an average of 3 per score.
Input the following query:
> db.scores.find({score: {$gt: 50} , score: {$lt: 60}}).count()
Expected result
--------------------
~27 +/- 5 (score: 51-59 is 9% of total, 9% of 300 is 27)
Actual result
----------------
171 # this is what I see; your result may be different, but roughly 177 +/- 13.
There are ways to do this query correctly, such as
> db.scores.find( { score :
{ $gt : 50 , $lt : 60 }} ).count( )
but the way described above should work, too.