NOT [DUPLICATE]: This question is NOT been previously answered and been unfairly downvoted. The two marked answers from different sources are about distinct things. Combined, they may partially answer to some degree but they don't address the very specific case of what is been asked here (e.g. None of them explains how to parse email before comparing to variable). I need to extract the first half of email, compare it to a string variable, and then execute the query with mongoose.
I found many partial answers for this question (/^([^@]*)/
) but nothing showing how to apply the filter to a search given string for a partial email field and in a Mongoose query.
With this I have a search (provided by user) but not the filter:
{ email: { $regex: search, $options: "i" } }
With this I have a filter but not the search:
{ email: { $regex: /^([^@]*)/, $options: "i" } }
I need to find a way to do both at same time in one go (to search only first half of email with given string variable). My intention is to disregard everything that comes after the @ symbol (including the @) which should not be included in a string variable ("search"). I need to find a way to insert search in the regex filter.
Again, it should ignore/exclude everything from '@' to the end of the email address (the search should not consider this part).
- search is a variable
Thanks in advance!