First things first, the correct query is:
{'$match' : {'location' : {'$geoWithin': {'$centerSphere': [[lng,lat], distance] }} }},
however the lng and lat above that I was passing were not floats but unicode chars so that threw the error.
Question
This is my aggregation:
query = [
{'$match' : { 'location' : {
'$geoWithin': {'$center' : [ [lng,lat], distance ] }} }}
]
dumps(DB.venue.aggregate(query))
However it throws:
OperationFailure: command SON([('aggregate', u'venue'), ('pipeline',
[{'$match': {'location': {'$geoWithin': {'$center': [[u'23.729310', u'37.983716'],
0.0023544184586407157]}}}}])]) failed: exception: Malformed geo query: { $geoWithin:
{ $center: [ [ "23.729310", "37.983716" ], 0.002354418458640716 ] } }
I have also tried with $within
instead of $geoWithin
and $centerSphere
instead of $center
but no. Typically the find() query works with within and center (docs).
Is it a bug or just not supported by pymongo? Because the java driver work fine with $geoWithin
and $centerSphere
.
Solution
First things first, the correct query is:
{'$match' : {'location' : {'$geoWithin': {'$centerSphere': [[lng,lat], distance] }} }},
however the lng and lat above that I was passing were not floats but unicode chars so that threw the error.