美文网首页
mongoDB 模糊查询

mongoDB 模糊查询

作者: 超凡陆战队 | 来源:发表于2016-08-23 17:23 被阅读7637次

从mysql转到mongodb,没有了sql一下子发现什么都不会了。今天就来说一下,查询中经常用到的模糊查询:

1.%xx%

   sql:

       select * from user where name like "%花%";

   mongo:

       db.user.find(name:/花/);

2.xx%

   sql:

      select * from user where name like "花%";

   mongo:

       db.user.find(name:/^花/);

3.不区分大小写

       db.user.find(name:/a/i);

       还可以用正则表达式来查询数据,mongo使用$regex来设置字段匹配正则表达式,其实上面就是简化版的正则表达式了。

具体怎么玩可以参考:

http://www.runoob.com/mongodb/mongodb-regular-expression.html

相关文章

网友评论

      本文标题:mongoDB 模糊查询

      本文链接:https://www.haomeiwen.com/subject/pylnsttx.html