最近遇到一个困难,mongoose模糊查询中带有括号查询不出来的问题,找了很久还是别人提点的
将括号等特殊字符替换为\转义字符进行查询就能查出结果
const test = '(4'
const escapedString = test.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
Model.find({ field: { $regex: escapedString } },
这样就可以查询出带括号等特殊字符的数据
最近遇到一个困难,mongoose模糊查询中带有括号查询不出来的问题,找了很久还是别人提点的
将括号等特殊字符替换为\转义字符进行查询就能查出结果
const test = '(4'
const escapedString = test.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
Model.find({ field: { $regex: escapedString } },
这样就可以查询出带括号等特殊字符的数据