runCommand with distinct and the db.xxx.distinct return different results when using $near in the query

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Cannot Reproduce
    • Priority: Major - P3
    • None
    • Affects Version/s: 2.2.2
    • Component/s: Geo, Querying
    • Environment:
      Amazon Linux AMI x86_64 EBS, Micro Instance (613 MiB memory)
    • Fully Compatible
    • ALL
    • Hide

      You have to run two queries, one using the db.runCommand with a distinct query that uses the $near operator, and the equivalent query written using the syntax _db.xxx.distinct. For example:

      db.runCommand ( { "distinct" : "advice" , "key" : "somekey" , "query" : { "latlon" : { "$near" : [ 59.333972499999994 , 18.057507599999997]} , "title" : { "$ne" : ""} , "text" : { "$ne" : ""} } } )
      
      db.advice.distinct('somekey', { "latlon" : { "$near" : [ 59.333972499999994 , 18.057507599999997]} , "title" : { "$ne" : ""} , "text" : { "$ne" : ""} })
      
      Show
      You have to run two queries, one using the db.runCommand with a distinct query that uses the $near operator, and the equivalent query written using the syntax _db.xxx.distinct. For example: db.runCommand ( { "distinct" : "advice" , "key" : "somekey" , "query" : { "latlon" : { "$near" : [ 59.333972499999994 , 18.057507599999997]} , "title" : { "$ne" : ""} , " text " : { " $ne " : " "} } } ) db.advice.distinct( 'somekey' , { "latlon" : { "$near" : [ 59.333972499999994 , 18.057507599999997]} , "title" : { "$ne" : ""} , " text " : { " $ne " : " "} })
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      The results given by runCommand with in a distinct query using the $near operator are different from the equivalent *db.advice.distinct* query.

      When we run the following command, we get 100 results:

      db.runCommand ( { "distinct" : "advice" , "key" : "somekey" , "query" : { "latlon" : { "$near" : [ 59.333972499999994 , 18.057507599999997]} , "title" : { "$ne" : ""} , "text" : { "$ne" : ""} } } )
      

      , and running the equivalent query using distinct returns only 75:

      db.advice.distinct('somekey', { "latlon" : { "$near" : [ 59.333972499999994 , 18.057507599999997]} , "title" : { "$ne" : ""} , "text" : { "$ne" : ""} })
      

      We don't understand why we get different results because the second query is a wrapper around the first one. In any case, we wanted to use the first query (runCommand) in the Java driver because it gives us the results that we need. Thus, we wrote the runCommand query in Java but the result that we got is the same as if we were using the db.advice.distinct query.

            Assignee:
            Siyuan Zhou
            Reporter:
            Kiko Fernandez
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: