I am trying to use Eve to query a MongoDB database with the geoNear aggregation operator, but I am getting the following when using aggregate variables:
'OperationFailure: geoNear command failed: { ok: 0.0, errmsg: "'near' field must be point", code: 17304, codeName: "Location17304" }'
The aggregation endpoint is set up in settings.py as follows:
geoAggr = {'datasource':{
'source':'geo',
'aggregation': {
'pipeline': [
{'$geoNear':{
'near': {'type':'Point', 'coordinates':['$lon', '$lat']},
'distanceField':'distance',
'maxDistance':'$maxDistance',
'spherical': True,
'query':{
'recentAnalyses.KeywordCombinationAll /300 v1':{
'$exists': True
}
}
}}
]
}
}}
It is queried using POSTMAN with a GET request to xxx.xxx.xxx.xxx:5000/geoAggr?aggregate={"$lon":"10.5","$lat":"10.5","$maxDistance":100000}.
If $lon and $lat are replaced by hard-coded values, the aggregator works perfectly, so it seems to be something to do with the way the variables are put into the aggregator. My first thought was that the numbers may be interpreted as strings, but the $maxDistance parameter works as expected.
Why is it not working with the variables?
It appears that variables inside arrays aren't replaced (I'm not sure if this is correct in all cases, but it is in this one), which makes sense.
Replacing 'coordinates':['$lon', '$lat'] with 'coordinates':'$coords' and accessing with xxx.xxx.xxx.xxx:5000/geoAggr?aggregate={"$coords":[10.5,10.5],"$maxDistance":100000} works.