Consider the following use case:
We are developing a new feature for our system that revolves displaying documents from the database on a map. We need to filter the documents by various criteria (not location) and then display the matching documents on a map.
In order to choose the center and zoom level of the map, we need the centroid of the returned records, and the radius that would contain them. Is there a way to retrieve that information using aggregation framework, or do I need to pull all records from MongoDB and do the calculation on our end?
It certainly seems like geoNear is the right solution for computing the distance on the last step so they can center their output, but there doesn't seem to be an easy way to do the centroid computation external to the pipeline and pass the resultant values into the geoNear call. Would it be feasible to remove that restriiction on geoNear so that it could be placed anywhere within an aggregation pipeline?