I am looking for a string in mongo that does not discriminate between lower and upper case, the problem is that if a record has a " " sign it does not find it.
{ username: { $regex: "ExamPle [email protected]", $options: "i" } } // does not work
{ username: { $regex: "[email protected]", $options: "i" } } // works
CodePudding user response:
You must escape the character " ".
Try something like this:
variable = "^ExamPle\\ [email protected]$"
db.testcollection.find({ username: { $regex: variable, $options: "i" } })
Look at the following link Case insensitive search in Mongo