Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

232
Views
Use variables in geonear aggregator in Python Eve with MongoDB

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?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!