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

$lte and $gt Query Operators not working properly for String Comparisions

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Critical - P2
    • Resolution: Works as Designed
    • 2.4.6
    • None
    • Querying
    • Fully Compatible
    • ALL
    • Hide

      1. Insert Some Names :
      > db.people.insert(

      {"name":"Adam"}

      )
      > db.people.insert(

      {"name":"Bob"}

      )
      > db.people.insert(

      {"name":"Charlie"}

      )
      > db.people.insert(

      {"name":"Dwayne"}

      )
      > db.people.insert(

      {"name":"Elika"}

      )

      2. Query for documents using $lt Query Operator to get all the documents having "name" starting with A,B and C.
      > db.people.find({"name":{"$lte":"C"}})
      Actual Output:

      { "_id" : ObjectId("5358dfdf8211b04a14804731"), "name" : "Adam" } { "_id" : ObjectId("5358dfe38211b04a14804732"), "name" : "Bob" }

      Expected Output:

      { "_id" : ObjectId("5358dfdf8211b04a14804731"), "name" : "Adam" } { "_id" : ObjectId("5358dfe38211b04a14804732"), "name" : "Bob" } { "_id" : ObjectId("5358dfe78211b04a14804733"), "name" : "Charlie" }

      It did not return the document where name is "Charlie".

      Similarly: $gt operator to get all the documents where name starts with Character greater than C, the following query behaves improperly and returns Charlie too. which was not expected.

      1. Should not return Charlie.
        > db.people.find({"name":{"$gt":"C"}})
        Actual Output: { "_id" : ObjectId("5358dfe78211b04a14804733"), "name" : "Charlie" } { "_id" : ObjectId("5358dfef8211b04a14804734"), "name" : "Dwayne" } { "_id" : ObjectId("5358dff78211b04a14804735"), "name" : "Elika" }

        Expected Output:

        { "_id" : ObjectId("5358dfef8211b04a14804734"), "name" : "Dwayne" } { "_id" : ObjectId("5358dff78211b04a14804735"), "name" : "Elika" }
      Show
      1. Insert Some Names : > db.people.insert( {"name":"Adam"} ) > db.people.insert( {"name":"Bob"} ) > db.people.insert( {"name":"Charlie"} ) > db.people.insert( {"name":"Dwayne"} ) > db.people.insert( {"name":"Elika"} ) 2. Query for documents using $lt Query Operator to get all the documents having "name" starting with A,B and C. > db.people.find({"name":{"$lte":"C"}}) Actual Output: { "_id" : ObjectId("5358dfdf8211b04a14804731"), "name" : "Adam" } { "_id" : ObjectId("5358dfe38211b04a14804732"), "name" : "Bob" } Expected Output: { "_id" : ObjectId("5358dfdf8211b04a14804731"), "name" : "Adam" } { "_id" : ObjectId("5358dfe38211b04a14804732"), "name" : "Bob" } { "_id" : ObjectId("5358dfe78211b04a14804733"), "name" : "Charlie" } It did not return the document where name is "Charlie". Similarly: $gt operator to get all the documents where name starts with Character greater than C, the following query behaves improperly and returns Charlie too. which was not expected. Should not return Charlie. > db.people.find({"name":{"$gt":"C"}}) Actual Output: { "_id" : ObjectId("5358dfe78211b04a14804733"), "name" : "Charlie" } { "_id" : ObjectId("5358dfef8211b04a14804734"), "name" : "Dwayne" } { "_id" : ObjectId("5358dff78211b04a14804735"), "name" : "Elika" } Expected Output: { "_id" : ObjectId("5358dfef8211b04a14804734"), "name" : "Dwayne" } { "_id" : ObjectId("5358dff78211b04a14804735"), "name" : "Elika" }

    Description

      db version v2.4.6
      git version: b9925db5eac369d77a3a5f5d98a145eaaacd9673

      Attachments

        Activity

          People

            Unassigned Unassigned
            prajjwal1988 Prajjwal
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: