mhe*_*gon 9 regex mongodb strongloop loopbackjs
有没有办法使用Diacritic-Case-Insensitive选项查询Loopback + MongoDB上的结果?
例如,如果我想搜索查询olimpic,并且数据库包含以下单词:
Olímpic
olimpic
Olimpic
Run Code Online (Sandbox Code Playgroud)
然后,所有上述内容都应作为结果返回.我尝试过下面列出的多个查询和其他组合,但到目前为止还没有任何工作.
{"where":{"name.text":{"like":"olimpic","options":"i"}}}
{"where":{"name.text":{"like":"/^olimpic$/i","options":"i"}}}
{"where":{"name.text":{"like":"/.*olimpic.*/i"}}}
{"where":{"name.text":{"regexp":"/.*olimpic.*/i"}}}
Run Code Online (Sandbox Code Playgroud)
任何的想法?
提前致谢!
从MongoDB版本3.1.7开始,你想要的文本索引应该是可能的.有关详细信息,请参阅SERVER-19557.早期版本无法处理变音符号.
设置文本索引相当简单:只需在要搜索的所有字段上创建索引 - 每个集合只能有一个文本索引:
db.yourCollection.createIndex(
{"name.text":"text","foo":"text"},
{"default_language":"french"}
)
Run Code Online (Sandbox Code Playgroud)
现在,要搜索索引,只需执行以下操作:
db.yourCollection.find(
{ $text: {$search:"Olimpic"} }
)
Run Code Online (Sandbox Code Playgroud)
哪个应该给你预期的结果.
心连心