Multi text search in mongoose
Published in
1 min readMay 1, 2019
I have a list of records with format like this “company name, company address”.
Usually the wildcard only apply to the whole text, but I want to enhance the search ability. If I type search text as “home depot toronto”, I want to see this in the results.
Home depot, 114 kennedy ave, Toronto, Ontario, L3A 1T4
Instead of %home depot toronto%,
I want to implement %home%depot%toronto%
Here is my solution.
/ /g to replace all space to .* ( global (g) modifier replace all occurrences)
i is for insensitive