我正在运行geoNear查询作为MongoDB聚合管道的一部分,我似乎无法设置足够大的maxDistance以返回所有结果 .

我有大约30000个文档的集合,所有文档都有有效的地理位置(格式为 [lng , lat] ),最多我只能得到大约9或1万个文档 .

当我在mongo shell中运行以下查询时,我得到大约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

注意,我已将maxDistance设置为大于地球的周长(我正在使用GeoJSON Point so maxDistance is in meters) . 我还确保limit和batchSize都大于我的集合中的文档数量 .

当将其作为查询查询运行时,我得到集合中完整文档数的计数 . 即

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

我还注意到,当更改要搜索的坐标值时,我会返回不同数量的文档,尽管指定了应包含所有内容的maxDistance .

我已经使用MongoDB的3.2.6和3.0.11版本重现了这种行为 .

对于聚合查询,我不知道maxDistance的值是否有上限?或者是否有其他限制返回文件数量的东西?我无法找到任何这些方案的文档 .