
一、不区分大小写的正则表达式
如果检索需要不区分大小写,我们可以设置 $options 为 $i。
以下命令将查找不区分大小写的字符串 runoob:
>db.posts.find({post_text:{$regex:"runoob",$options:"$i"}})集合中会返回所有包含字符串 runoob 的数据,且不区分大小写:
{
"_id" : ObjectId("53493d37d852429c10000004"),
"post_text" : "hey! this is my post on runoob",
"tags" : [ "runoob" ]
}二、有个正则表达式,java代码就好写了
在springboot项目中使用mongodb
1、引入jar包
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-mongodb</artifactId> <version>2.0.1.RELEASE</version> </dependency>
2、引入MongoTemplate对象
@Autowired private MongoTemplate mongoTemplate;
3、不分区大小写查询,其中操作符“i”:表示不分区大小写
JSONObject ethInfo = mongoTemplate.findOne(new Query(Criteria.where("car_brand_type").regex(carBrandType,"i")),
JSONObject.class, "car_info");众多python培训视频,尽在python学习网,欢迎在线学习!






