Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-11972

$gt and $lt do not combine with some syntax in mongodb shell

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      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(

      { 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.

            Assignee:
            Unassigned Unassigned
            Reporter:
            william.cross William Cross
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: