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

402
Visualizações
Mongodb Search geolocation with text filters and group by in a single query

enter image description here We are using Mongo database for insert jobs related data. I want to get the count according to GEO location coordinates with text search on title and description fields.

Suppose we have records

id title                   coordinates[0]       coordinates[1]
--+-----------------------+---------------------+----------------
1  PHP developer          | 97.77               | -92.99
2  Laravel developer,php  | 97.77               | -92.99
3  python                 | 97.77               | -92.99
4  Rails                  | 23.77               | -34.99
5  Python, php            | 23.77               | -34.23

User search with "PHP" (title), latitude-longitude coordinates and specific with distance 50 miles, If the distance came in first 3 records id[1,2,3] and PHP title came in first two records id[1,2] then user will get result as a count 2. How can we make a query for this in mongo database or PHP mongo database driver query? We are going to attach our database structure as an image. If you have any query let us know. Thanks in advance.

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

In Mongodb/Driver/Query it can be used like this

    $queryString = [
                    [
                        '$geoNear'=> [
                        'near'=> [ 'type'=> "Point", 'coordinates'=> [-73.86, 41.07 ] ],
                        'distanceField'=> "dist.calculated",
                        'maxDistance'=> '5000',
                        'includeLocs'=> "dist.location",
                        'num'=> 10000,
                        'spherical'=> true,
                        'query' => ['title'=> ['$regex' => 'sales' ]]
                        ]
                    ],
                    ['$unwind'=> '$loc'],    
                    ['$group'=>['_id'=> '$loc', 'count'=>['$sum'=>1]]],
                    ['$project'=>['res'=>['loc'=>'$_id', 'count'=>'$count']]], 
                    ['$group'=>['_id'=>null, 'total'=>['$sum'=>1], 'data'=>['$addToSet'=>'$res']]],
                ];
     $conn = new \MongoDB\Driver\Manager("mongodb://username:password@localhost:2702/admin");
     $command = new \MongoDB\Driver\Command([
                'aggregate' => 'collection_name',
                'pipeline' =>  $queryString 
            ]);

    $result = $conn->executeCommand('mongodbname', $command);
over 4 years ago · Santiago Trujillo Relatório

0

Try this:

db.crawled_jobs.aggregate([{ "$geoNear": {"near": { "type": "Point", "coordinates": [  -73.86,  41.07  ]  },"spherical": true,"maxDistance": 500000,
 "distanceField": "distance","query": {"title": /php/}}}])
over 4 years ago · Santiago Trujillo Relatório

0

check this sardar ji :

db.hotels.find({ "$text": { "$search": "test" }, "location": { "$geoWithin": { "$centerSphere": [[ 72.867804, 19.076033 ], 5000 ] } }})

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