Start a new topic

Problem with compound query including $nearSphere

Hi there --



I can get this to return correctly --

/appdata/kid_Pe92rIpdB9/person/?query={"_geoloc":{"$nearSphere":[-80.0367259,40.4828051],"$maxDistance":200.0}}&resolve_depth=1&limit=10



however, once I compound other queries (like so):

/appdata/kid_Pe92rIpdB9/person/?query={"$and":[{"hideAge":{"$ne":false}},{"_geoloc":{"$nearSphere":[-80.093822737599851,40.618027479897073],"$maxDistance":200.0}}]}&resolve_depth=1&limit=10



I get this error from the API console:

"can't find any special indices: 2d (needs index), 2dsphere (needs index), for: { $and: [ { _geoloc: { $nearSphere: [ -80.09382273759985, 40.61802747989707 ], $maxDistance: 200 } }, { hideAge: { $ne: false } } ] }"



I seem to be able to compound any queries I'd like until I add a $nearSphere request and I'm at a bit of a loss -- any idea what could be going on/how to get it working?


(the underscore before geoloc was stripped from my answer)
Hi Calvin,



You've run into a known bug with MongoDB, our underlying database, which does not allow you to use the $and operator in combination with a geospatial query. However, you can perform an implicit AND operation by simply combining the objects in the array:



/appdata/kid_Pe92rIpdB9/person/?query={"hideAge":{"$ne":false},"geoloc":{"$nearSphere":[-80.093822737599851,40.618027479897073],"$maxDistance":200.0}}&resolvedepth=1&limit=10
Login or Signup to post a comment