I'm trying to work with mongoose to implement a simple search feature that I plan to expand later.
Basically what I'm trying to do is take a search query from the user and put it inside the mongoose find() query, but I'm using the built-in " regular expression" way according to their documentation:
MyModel.find({ name: /john/i }, null, { skip: 10 })
Here, john is a static value, when I try to place a variable instead it doesn't work.
MyModel.find({ name: /req.query.name/i }, null, { skip: 10 })
How can I place a variable instead of the static content?
P.S: I tried using the JS regular expression and it did work but I want to do it the mongoose way.
MyModel.find({ name: new RegExp(req.query.name, "i") }, null, { skip: 10 }) //this works