Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

135
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!