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

315
Views
Mongoose with search autocomplete index

I want an autocomplete search on a name field in my collection on MongoDB Atlas. I've configured a search index in MongoDB atlas as following:

{
  "mappings": {
    "dynamic": false,
    "fields": {
      "name": {
        "foldDiacritics": false,
        "maxGrams": 8,
        "type": "autocomplete"
      }
    }
  }
}

and I'm trying to search via mongoose a substring in the entire collection like this:

collection.aggregate([
    {
      $search: {
        autocomplete: {
          path: 'name',
          query: query,
        },
      },
    },
    {
      $limit: 10,
    },
    {
      $project: {
        _id: 0,
        name: 1,
      },
    },
  ]);

I always get 0 results, does anyone can help me understand what am I doing wrong?

Thanks, Erez

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The problem was that I've changed the default index name (which is 'default') and in that case, I needed to specify the new index name in the query or change the index to be named 'default'. Didn't found any mention of that in the MongoDB documentation though.

over 4 years ago · Santiago Trujillo 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!