I have searched similar problems but I did not find a solution
const keyword = "test("
db.auto_complete.find({keyword:{$regex: new Reg Exp('^'+keyword) }})
if variable keyword does not container a ( it works
But if the variable keyword includes a ( I get the error
Invalid regular expression: /^test(/ : Unterminated group
How to solve it?
You should try to escape the parentheses with a \. Otherwise it Regex will interpret it as an operator used for matching or grouping.
const keyword = "test\("