In my aggregation pipeline I eventually get an array of store IDs, the next step is to run a lookup and get the stores documents but I need to limit them to a 10km max distance.
The problem I’m facing is that, for some reason, I get an error saying that “$geoNear is only valid as the first stage in a pipeline.”, even though it is the first stage in the $lookup pipeline.
Lookup stage:
{
from: "stores",
localField: "stores",
foreignField: "_id",
pipeline: [
{
$geoNear: {
near: {
type: "Point",
coordinates: [0, 0]
},
distanceField: "distance",
maxDistance: 10000
}
}
],
as: "stores"
}
Not sure what I’m missing here.