MongoDb $near incongruent result on 1 meter variation of $maxDistance

27 views Asked by At

I have set a 2dSphereIndex on a field named location, performing the same $near query with the smallest (1 meter) variation on $maxDistance leads to total different results:

First query:

db.collection.find(
{
   "location":{
      "$near":{
         "$geometry":{
            "type":"Point",
            "coordinates":[
               12.0,
               0.2
            ]
         },
         "$maxDistance":3724073
      }
   }
})
.limit(100).explain("executionStats");

Stats first query:

"executionTimeMillis" : 0,
"totalKeysExamined" : 4,
"totalDocsExamined" : 0,

Second query:

db.collection.find(
{
   "location":{
      "$near":{
         "$geometry":{
            "type":"Point",
            "coordinates":[
               12.0,
               0.2
            ]
         },
         "$maxDistance":3724074
      }
   }
})
.limit(100).explain("executionStats");

Stats second query:

"executionTimeMillis" : 411, 
"totalKeysExamined" : 56473,
"totalDocsExamined" : 56471,
...

The points are scattered all over the countries starting from a certain latitude so I would not expect an impact of 50,000+ elements on a meter variation.

Additional question, why does $near not apply the limit condition directly on the index during scan, but afterwards?

Additional details: "dbVersion":"4.4.4","isEnterprise":false

Cheers

0

There are 0 answers