[SERVER-11972] $gt and $lt do not combine with some syntax in mongodb shell Created: 05/Dec/13  Updated: 05/Dec/13  Resolved: 05/Dec/13

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

Type: Bug Priority: Major - P3
Reporter: William Cross Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

mongodb 2.4.8


Operating System: ALL
Participants:

 Description   

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(

{ score : Math.floor( Math.random() * 100 + 1), student : i , type : score_types[ j ] }

) } }

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.



 Comments   
Comment by Scott Hernandez (Inactive) [ 05/Dec/13 ]

What you are describing is how javascript object/dicts work (in fact most languages have this behavior in their map/dict/hash impls):

> x = {a:2, a:1}
{a:1}

You cannot have repeated fields of the same name at the same level.

Generated at Thu Feb 08 03:27:15 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.