0

I have an object like this

{
   "_id":2939399,
   "name:"Lionel Messi"
} 

want the searches: Lio, nel, ssi, Lionel, Mess, Lione, Messi, etc ... (All substrings that are more than 3 characters long) will yield me this result(Lionel Messi object)- how that can be achieved?

I have tried to put an index on the name field bit this works partially and gives me results only when I search Messi or Lionel..

kedar sedai
  • 1,687
  • 3
  • 16
  • 25
MD10
  • 1,313
  • 3
  • 12
  • 35
  • Have you considered using regex for the partial search? – DaveStSomeWhere Mar 22 '20 at 02:05
  • Does this answer your question? [Checking if a field contains a string](https://stackoverflow.com/questions/10610131/checking-if-a-field-contains-a-string) – glinda93 Mar 22 '20 at 07:17
  • Does this answer your question? [mongodb find a pattern of an input](https://stackoverflow.com/questions/60787323/mongodb-find-a-pattern-of-an-input) – Valijon Mar 22 '20 at 09:56
  • This is my post , so NO – MD10 Mar 22 '20 at 10:11
  • _"I have tried to put an index on the name field bit this works partially and gives me results only when I search Messi or Lionel."_: That is you have tried a [text search](https://docs.mongodb.com/manual/text-search/index.html). Searching a part of the string of "Lionel" or "Messi" requires using a [regex search](https://docs.mongodb.com/manual/reference/operator/query/regex/index.html). Regex searches may or may not use indexes effectively. – prasad_ Mar 23 '20 at 02:38

0 Answers0