2

I'm running a geoNear query as part of a MongoDB aggregation pipeline, and I can't seem to set a maxDistance large enough that all the results are returned.

I have a collection of about 30000 documents, all with valid geo locations (in the format [lng , lat]), and at most I can only seem to get about 9 or 10 thousand documents back.

When I run the following query in the mongo shell, I get a count of about 9000:

 db.myCollection.aggregate(
  [{"$geoNear": {"near" : {"type" : "Point", 
                           "coordinates": [-0.1, 50.5]},
                 "distanceField": "data.distance", 
                 "spherical": true, 
                 "maxDistance":100000000
                 "limit":100000}}],    
   {"cursor": {"batchSize": 100000000}}).itcount()  // => ~9000

Note, I've set the maxDistance to larger than the circumference of the earth (I'm using GeoJSON Point so maxDistance is in meters). I've also ensured that the limit and batchSize are both greater than the number of documents in my collection.

When running this as a find query I get the count of the full number of documents in the collection. i.e.

 db.myCollection.find({"data.location": 
                               {$near: {$geometry: {type: "Point",                               
                                                    coordinates: [-0.1, 50.5]}, 
                                        $maxDistance: 100000000}}}).count() // => ~30000

I also notice that when changing the value of the coordinates to search from, I get back different numbers of documents, despite specifying a maxDistance that should encompass everything.

I've reproduced this behaviour with versions 3.2.6 and 3.0.11 of MongoDB.

Is there an upper limit to the value of maxDistance that I don't know about for the aggregate querying? Or is there something else that's restricting the number of documents returned? I haven't been able to find any documentation for either of these scenarios.

Community
  • 1
  • 1
johncowie
  • 317
  • 1
  • 2
  • 7
  • Possible duplicate of [mongodb geoNear vs near](http://stackoverflow.com/questions/15537611/mongodb-geonear-vs-near) – styvane Jun 03 '16 at 16:54

0 Answers0