I'm trying to do a geoNear + text search aggregate query in Mongoose:
landmarkSchema.aggregate(
[
{ "$geoNear": {
"near": {
"type": "Point",
"coordinates": [parseFloat(userCoord1), parseFloat(userCoord0)]
},
"distanceField": "distance",
"minDistance": 1,
"maxDistance": 5000,
"spherical": true,
"query": { "loc.type": "Point" }
} },
{ $match: { $text: { $search: sText } } },
{ $sort: { score: { $meta: "textScore" } } }
],
function(err,data) {
if (data){
res.send(data);
}
else {
console.log('no results');
res.send({err:'no results'});
}
});
But Mongo is not returning any results. When I perform each query separately, $geoNear
and $match : $text
the correct results are returned. Am I chaining the query incorrectly?