0

I want to be able to use $regex to be able to find any words that contain certain keyword given by user, but it is not working. I have this:

aggregatePipeline.push({
      $match: {
        name: {
          $regex: `/${name.toLowerCase()}/`,
        },
      },
    });

I tried using $regexMatch, but it says it is not supported for free tier. Is there a work around?

{
      $regexMatch: {
        input: "$name",
        regex: `/${name}/`,
      },
}

I'm trying to avoid $regexMatch at least for now due to free tier.

I am able to retrieve user by the exact name, but I also want to retreive all names that have a substring ex. 'ger', should retrieve 'Gerry', 'Gerald', 'anger'....

aggregatePipeline.push({ $match: { name: name.toLowercase() } });

Thanks a lot!

1 Answer 1

2

{ 'search field': { $regex: new RegExp('search name', 'gi') } }

Sign up to request clarification or add additional context in comments.

2 Comments

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
Thank you, I found out I could use $match: { name: { $regex: .*${name.toLowerCase()}.* } } , also using your approach I would need to add $match which code will end up like this: $match: { name: { $regex: new RegExp(${name.toLowerCase()}, "gi"), }, }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.