-1

I've found a similar question and the answer in it didn't turn out to be working for me.
I want to do something like:

ItemModel.find({name: \^VARIABLEHERE\i});

doing a case insensitive search that finds anything that matches the variable.
Also I tried to do something on my own by using:

new RegExp(`/^${variablehere}/`, 'i')

And

new RegExp(`/^${variablehere}/i`)

Yeah I'm new to regular expressions.
All help is appreciated. :)

1 Answers1

0

You can use $regex

ItemModel.find({
    name: {
        $regex: '.*' + name + '.*', //or you can use `.*${name}.*`
        $options: 'i'
    }   
});

There is a complete manual for variety of regular expression at mongodb $regex manual

Guru Prasad mohapatra
  • 1,809
  • 13
  • 19