[SERVER-8888] runCommand with distinct and the db.xxx.distinct return different results when using $near in the query Created: 07/Mar/13  Updated: 21/Jul/15  Resolved: 07/Jan/15

Status: Closed
Project: Core Server
Component/s: Geo, Querying
Affects Version/s: 2.2.2
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Kiko Fernandez Assignee: Siyuan Zhou
Resolution: Cannot Reproduce Votes: 0
Labels: distinct, near, runCommand
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Amazon Linux AMI x86_64 EBS, Micro Instance (613 MiB memory)


Issue Links:
Tested
Backwards Compatibility: Fully Compatible
Operating System: ALL
Steps To Reproduce:

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" : ""} })

Participants:

 Description   

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.



 Comments   
Comment by Siyuan Zhou [ 07/Jan/15 ]

Hi kikofernandez, we haven’t heard back from you for some time, so I’m going to mark this ticket as resolved. If this is still an issue for you, feel free to re-open the ticket and provide additional information.

Regards, Siyuan

Comment by Siyuan Zhou [ 08/Dec/14 ]

Hi kikofernandez, we still need the reproduction to diagnose the problem. If this is still an issue for you, can you please send us the sample data so we can reproduce it?

Thanks, Siyuan

Comment by Siyuan Zhou [ 30/Oct/14 ]

Hi kikofernandez,

Thank you for your report.

I tried to generate the data and reproduce this issue with the following code.

db.geo2d.drop()
db.geo2d.ensureIndex({latlon: "2d"})
for (var i = 0; i < 1000; i++) {
  var doc = { latlon: [59.333972499999994 + 0.01 * i , 18.057507599999997 - 0.01 * i], title: "hello", text: "text" + i, somekey: i % 10 }
  db.geo2d.insert(doc);
}
 
var res = db.runCommand({
  "distinct": "geo2d",
  "key": "somekey",
  "query": {
    "latlon": {
      "$near": [59.333972499999994, 18.057507599999997]
    },
    "title": {
      "$ne": ""
    },
    "text": {
      "$ne": ""
    }
  }
})
 
printjson(res);
 
res = db.geo2d.distinct('somekey', {
  "latlon": {
    "$near": [59.333972499999994, 18.057507599999997]
  },
  "title": {
    "$ne": ""
  },
  "text": {
    "$ne": ""
  }
})
 
printjson(res)

But I am not able to reproduce this problem with 2.2.7 and 2.7.8. If you still encounter this problem, please attach the sample data to this ticket so that we can reproduce it.

Thanks,
Siyuan

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