-
Type: Bug
-
Resolution: Incomplete
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Aggregation Framework, Geo
-
None
-
ALL
-
We had our server running Mongo v3.0 and $geoNear worked fine.
When we have upgraded it to Mongo v3.2 and we started getting issues with $geoNear.
Our application has some Point of Interests spread throughout the city kept in a collection with 2dsphere index. We query the DB using aggregation query with $geoNear as mentioned below.
[ { '$geoNear': { near: [ lng, lat ], distanceField: 'distance', spherical: true, num: 10000, maxDistance: 0.007848061528802385, query: { status: 'active', 'location.geofence': { '$exists': false } } } } , { '$match': { '$or': [ { name: { '$regex': 'search', '$options': 'i' } }, { 'location.locality': { '$regex': 'search', '$options': 'i' } }, { keywords: { '$regex': 'search', '$options': 'i' } } ] } } , { '$project': { _id: 1, name: 1, rating: '$ratings.overall', 'location.locality': '$location.locality', 'location.coordinates': '$location.coordinates', 'location.coords': '$location.coords', distance: '$distance' } } , { '$sort': { distance: 1 } } ]
This query is supposed to get all the point of interests within a radius of 50 Kms. But when I simulate the user's location and run the queries, I get a plot as given below.
Though there are multiple documents distributed throughout the city, there is only one document matching the above query whose location is marked by Blue dot. And the matrix shows the customer locations with green dot where the document is returned and red dot where the document is not returned for the query. So clearly point of interest is shown in places which are 49 kms away and sparsely populated documents but not within 10 kms away and densely populated documents.
This seems to have introduced because of the optimizations mentioned here
https://www.mongodb.com/blog/post/geospatial-performance-improvements-in-mongodb-3-2