我在 mongo 中尋找一個不區分大小寫的字串,問題是如果記錄有一個“ ”號,它就找不到它。
{ username: { $regex: "ExamPle [email protected]", $options: "i" } } // does not work
{ username: { $regex: "[email protected]", $options: "i" } } // works
uj5u.com熱心網友回復:
您必須轉義字符“ ”。
嘗試這樣的事情:
variable = "^ExamPle\\ [email protected]$"
db.testcollection.find({ username: { $regex: variable, $options: "i" } })
看下面的鏈接Mongo 中不區分大小寫的搜索
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/365117.html
