Does $geoNear query in MongoDB aggregate pipeline restrict number of documents?
<p>I'm running a <em>geoNear</em> 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.</p>

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

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

<pre><code> 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()  // =&gt; ~9000
</code></pre>

<p>Note, I've set the <em>maxDistance</em> to larger than the circumference of the earth (I'm using GeoJSON Point <a href="https://docs.mongodb.com/manual/reference/operator/aggregation/geoNear/" rel="nofollow">so maxDistance is in meters</a>).  I've also ensured that the <em>limit</em> and <em>batchSize</em> are both greater than the number of documents in my collection.</p>

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

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

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

<p>I've reproduced this behaviour with versions 3.2.6 and 3.0.11 of MongoDB.</p>

<p>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.</p>