我想搜索文档中具有特殊字符(例如“+”)的值。
variable = 'test+test.test';
Run Code Online (Sandbox Code Playgroud)
我想用 搜索值.*variable.*,
例如,
db.myCollection.find({ myKey : { '$regex' : '.*variable.*','$options' : 'i' });
Run Code Online (Sandbox Code Playgroud)
以上查询不起作用
我已经解决了问题,这是工作代码。
string = "abcd+1234@gmail.com";
Meteor js query example: {'emails.address': {'$regex': '.*' + Helpers.escapeRegExp(string) + '.*', '$options': 'i'}},
escapeRegExp: function (string) {
if (string) {
return string.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
}
}
It should be abcd\+1234@gmail\.com after call escapeRegExp function.Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9301 次 |
| 最近记录: |