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

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

    • Type: Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Priority: Icon: Major - P3 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 " : " "} })

      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@mongodb.com Siyuan Zhou
            Reporter:
            kikofernandez Kiko Fernandez
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: