Ok, I think I understood the solution. Turns out you can use either a dot / radius or a bounding box in the same query.
max_distance = int(haversine(sw_lat, sw_lon, self.centroid.y, self.centroid.x))
self.new_query = {
'$and': [
{'point': {
'$geoWithin': {"$box": box }
}},
{'point': OrderedDict([
('$geoNear', {
'$geometry': {
'type': 'Point' ,
'coordinates': [self.geo.centroid.coords[0], self.geo.centroid.coords[1]]
},
'$maxDistance': max_distance
}),
])}
]
}
source
share