Case insensitive Search not working

So i’ve created index for product_name of products collection and i am using this query on nodejs to search for products:
Product.find({ $text: { $search: "${req.body.value}", $caseSensitive: false } });
now the problem here is that the search returns product only when a word is complete e.g.:

  • “smart watch” // product name
  • here query for “smart” works but “smar” does not work, in short i have to provide full word for it to return some result

Hello @Avelon_N_A ,

Welcome to The MongoDB Community Forums! :wave:

The behaviour you have described appears to match what is mentioned in the below blob from the $text documentation with regards to stemmed words:

Stemmed Words

For case insensitive and diacritic insensitive text searches, the $text operator matches on the complete stemmed word. So if a document field contains the word blueberry, a search on the term blue will not match. However, blueberry or blueberries will match.

If this is an Atlas deployment, you can take a look at Atlas search as it provides the autocomplete feature which performs a search for a word or phrase that contains a sequence of characters from an incomplete input string. You can also take a look at below blog which could help you in setting up partial search with Atlas search

In case you are interested in Atlas search and want to migrate your data from on-prem deployment to Atlas search you can follow

Additional resource to learn more about $regex, $text and Atlas search, please refer

Regards,
Tarun

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.