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

131
Visualizações
Find word in sentence with MongoDB text search

I developped a text search with mongodb and nodejs for a school project but i got a problem with it. I have in my database a place with the name "L'Atomium" but when i search "Atomium",mongodb doesn't find it,is there anyway that he does? My db looks like this:

{
  "name": "",
  "coordinate": "",
  "rating": 0,
  "commentaries": "",
  "description": ""
}

and my code for the text search looks something like this:

const dbo = db.db('mydb');
dbo.collection("places").createIndex({name: "text"}).then(r => {
      dbo.collection("places").find({"$text": {"$search": wordlist,"$caseSensitive": false,
                        "$diacriticSensitive": false }}).toArray((err,placelist) => {
                               *rest of the code*

Sorry if the question is not clear,i'm a total beginner with Stack Overflow. Thank you!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It actually isn't possible to find suffixes with text indices in MongoDB this way. You may be able to try something like

dbo.collection("places").find({$or: [{$text: {$search: "Atomium"}}, {foo: {$regex: "^Atomium"}}]})

However, the performance and results compiled from such a query will still not yield the best possible outcome.

If you are hosting your MongoDB database with MongoDB Atlas and you want full-text search capabilities, look into $search with Atlas https://docs.atlas.mongodb.com/atlas-search/. Its scoring and search capabilities are far beyond that of $text search.

A query using Atlas $search might look something like.

dbo.collection("places").aggregate([
    {
        $search: {
            query: "Atomium",
            path: "name",
            fuzzy: { maxEdits: 2 }
        }
    }
]);
about 4 years ago · Juan Pablo Isaza 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