I need to get documents within a specific radius which match a simple query.
The query works well in Robomongo:
db.getCollection('Options').aggregate([
{"$geoNear":
{"near": {"type":"Point","coordinates":[-0.1251485,51.5174914]},
"spherical":true,"distanceField":"dist","maxDistance":2000,
"query": {
"field": "xxx"
}}
},
{"$sort":{"dist":-1}}])
but returns an empty result in Meteor. I have tried different fields and queries.
Options.aggregate([
{"$geoNear": {
"near": {"type":"Point","coordinates":[-0.1251485,51.5174914]},
"spherical":true,"distanceField":"dist","maxDistance":2000,
"query": {
"field": "xxx"
}
}},
{"$sort":{"dist":-1}}
], (err, res) => {
console.log(err);
console.log(JSON.stringify(res));
});
I have also tried to use $match in the aggregation pipeline instead - works in Robomongo, empty result in Meteor.
Options.aggregate([
{$geoNear: {
"near": {"type":"Point","coordinates":[-0.1251485,51.5174914]},
"spherical":true,"distanceField":"dist","maxDistance":2000
}},
{$match: {"field": "xxx"}},
{$sort:{"dist":-1}}
], (err, res) => {
console.log(err);
console.log(JSON.stringify(res));
});
In fact, any $match aggregation seems to be empty.
Thanks a lot for your help & ideas!
–
- Same results with Options.rawCollection().aggreate(…) or when checking the results only instead of writing a callback