Mongo中不区分大小写的搜索 [英] Case insensitive search in Mongo
问题描述
我在Mongo中使用不区分大小写的搜索,类似于 https://stackoverflow.com/q/5500823/1028488 .
I am using a case insensitive search in Mongo, something similar to https://stackoverflow.com/q/5500823/1028488.
即我正在使用带有选项i的正则表达式.但是我在将正则表达式限制为该单词时遇到了麻烦,它的执行效果更像是SQL中的赞"
ie I am using a regex with options i. But I am am having trouble restricting the regex to just that word, its performs more like a 'Like' in SQL
例如:如果我使用类似的查询
{"SearchWord" : { '$regex' : 'win', $options: '-i' }}
,它向我显示获胜,窗口&的结果冬天.我如何将其限制为jsut show win?
eg: if I use query like
{"SearchWord" : { '$regex' : 'win', $options: '-i' }}
, it shows me results for win, window & winter. How do i restrict it to jsut show win?
我尝试了/^win$/
,但是说出无效的杰森....请提出一种方法.
I tried /^win$/
but its sayin invalid Json.... Please suggest a way.
预先感谢
推荐答案
您可以使用'$regex':'^win$'
或/^win$/i
(注意第二个引用不加引号)
You can use '$regex':'^win$'
or /^win$/i
(notice no quote on the second one)
此处来源:使用Mongo查询的正则表达式
这篇关于Mongo中不区分大小写的搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!