Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

234
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda