Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

231
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda