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

472
Visualizações
MongoDB Atlas - $search v/s $match

I'm building a web app using Node and MongoDB Atlas. I need to implement a search bar, which will be used to search a MongoDB collection in 2 particular fields. I was doing some research on the best way to build this, but the Mongo docs are slightly confusing.

These docs for Atlas Search mention a $search aggregation stage. On the other hand, these docs for MongoDB Aggregation Stages have no mention of the $search stage at all.

I want the search to be 'fuzzy', and this answer says this should be done using the regex, but I couldn't find any reference for a $regex operator in the Atlas Search docs. For a previous task, I created an aggregation pipeline in which I used the $match operator with db.collection.aggregate(). It seems to me that the $match operator should work just fine for the fuzzy search bar as well, since it would allow me to use the $regex operator. I believe $match can also take advantage of any indexes you might create on Atlas for your queries.

So my question is basically this - What's the difference between using $search and $match? Does one offer performance/cost benefits over the other? Or are they for different use cases which I'm totally missing? If using $search is the way to go, how would one make the query such that it's fuzzy? I will be grateful for any help.

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

0

$search is the best option for implementing search functionality. It will produce more accurate results, it will offer features like highlighting and autocomplete, and will be more performant for this use case.

As you work through the implementation, here are the docs.

Here is what a simple query with fuzzy matching will look like, with the defaults for the fuzzy setting:

{
  $search: {
    "index": <index name>, // optional, defaults to "default"
    "text": {
      "query": "queryText",
      "path": "<fields-to-search>",
      "fuzzy": {
         "maxEdits": 2
       }
    }
  }
}
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