Mongo $ geoNear query - invalid nscanned number and incorrect results

I have a collection with about 6k documents with a 2dsphere index in the location field, an example below:

"location" : {
    "type" : "Point",
    "coordinates" : [ 
        138.576187, 
        -35.010441
    ]
}

Using the following query, I get about 450 documents returned with nscanned around 3k. Each document has a place, many places are duplicated. Distances returned from GeoJSON are in meters, and a distance multiplier of 0.000625 converts the distances to miles. To check, I expect a maximum distance of 32180000000000 to return all documents on the planet, i.e. 6000

db.x.aggregate([
{"$geoNear":{
    "near":{
        "type":"Point",
        "coordinates":[-0.3658702,51.45686]
    },
    "distanceField":"distance",
    "limit":100000,
    "distanceMultiplier":0.000625,
    "maxDistance":32180000000000,
    "spherical":true,
}}

])

6000 ? . : " geoNear , , , -".

+4
1

, mongodb 16 $GeoNear. https://github.com/mongodb/mongo/blob/master/src/mongo/db/commands/geo_near_cmd.cpp , , ,

// Don't make a too-big result object.
if (resultBuilder.len() + resObj.objsize()> BSONObjMaxUserSize) {
    warning() << "Too many geoNear results for query " << rewritten.toString()
              << ", truncating output.";
    break;
}

https://github.com/mongodb/mongo/blob/master/src/mongo/bson/util/builder.h , 16 .

const int BSONObjMaxUserSize = 16 * 1024 * 1024;
+1

All Articles