MongoDB 模糊查询的语法是怎样的呢?
-
我现在想要实现关系数据库中如下查询功能,在MongoDB中应该怎么写呢?
- Like '%a%'
- Like 'a%'
- Like '%a'
- Like 'a%a'
-
@jesseshi 說:
Like '%a%'Like 'a%'Like '%a'Like 'a%a'
使用 regex
%a% => /a/
a% => /^a/
%a => /a$/
a%a => /^a.*a$/
-
$regex 的用法請參考
https://docs.mongodb.com/manual/reference/operator/query/regex/
-
剛好用到,之前忘光, 有這論壇查詢真方便