I have a query that’s supposed to do the following:
Take two sets of coordinates and return the locations that are near any of the coordinates.
I’m working on Node.js with Mongoose.js.
The original query code is below (before I tried using the query.or() syntax:
query.or([{geoNear: "loc", near: start, spherical: true},{geoNear: "loc", near: end}]);
The issue seems to be using the $or because I initially tried the code as:
that.count({
_cat: _cat ,
$or: [
{
loc: { $nearSphere: start }
},
{
loc: { $nearSphere: end }
}
]}, function(err, c) {
// do something
});
When I search using one location without the $or (i.e. start or end) I am able to get results. That is how I’m certain that the problem is with the $or.
Does mongoDB/mongoose support using $or with geospatial search, or am I doing something wrong?
It seems that
$ordoes not work, so I have opted for running 2 queries for now, then evaluating the result of each in order to return the count. It works for me because I don’t need the actual count, but I need to know if there are any locations available within a certain distance of each point.If anyone has a similar problem, and use this approach as a work-around, remember to nest the second query in the callback of the first query. This is obviously more problematic when you have more than 2 locations that you’re querying.