Quantcast
Viewing latest article 42
Browse Latest Browse All 48

Answer by Shubham Kakkar for How to query MongoDB with "like"?

     { $text: { $search: filter } },   );   if (indexSearch.length) {     return indexSearch;   }   return UserModel.find(     {       $or: [         { firstName: { $regex: `^${filter}`, $options: 'i' } },         { lastName: { $regex: `^${filter}`, $options: 'i' } },         { middleName: { $regex: `^${filter}`, $options: 'i' } },         { email: { $regex: `^${filter}`, $options: 'i' } },       ],     },   );

I used combination of regex and "index"


Viewing latest article 42
Browse Latest Browse All 48

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>