mongodb and 和 or 查询
db.getCollection('gxyWarnEntity').find({ "schoolId" : "f11c8ea12f457dbc19c768a8bb6357f8", "batchId" : "594f724d6974c107bd702cc6ef39183a", "$or" : [{ "studentName" : { "$regex" : "小", "$options" : "" } }, { "teacherName" : { "$regex" : "小", "$options" : "" } }] })
java:
public List<GxyWarnEntity> selectWarnPage(GxyWarnEntity gxyWarnEntity){
Criteria cri =Criteria.where("schoolId").is(gxyWarnEntity.getSchoolId());
if(gxyWarnEntity.getBatchId()!=null) {
cri.and("batchId").is(gxyWarnEntity.getBatchId());
}
if(gxyWarnEntity.getDepId()!=null){
cri.and("depId").is(gxyWarnEntity.getDepId());
}
if(gxyWarnEntity.getWarningType()!=null){
cri.and("warningType").is(gxyWarnEntity.getWarningType());
}
if(gxyWarnEntity.getStudentName()!=null){
cri.orOperator(Criteria.where("studentName").regex(gxyWarnEntity.getStudentName()),
Criteria.where("teacherName").regex(gxyWarnEntity.getStudentName())
//,Criteria.where("classTeacherName").regex(gxyWarnEntity.getStudentName())
);
}
Query query = new Query(cri);
if (gxyWarnEntity.getCurrPage() != null && gxyWarnEntity.getPageSize() != null) {
query.skip((gxyWarnEntity.getCurrPage()-1)*gxyWarnEntity.getPageSize())
.limit(gxyWarnEntity.getPageSize());
}
return template.find(query, GxyWarnEntity.class);
}
and:
db.getCollection('gxyWarnEntity').find({ "schoolId" : "f11c8ea12f457dbc19c768a8bb6357f8", "batchId" : "", "$and" : [{ "warningType" : { "$gte" : 1 } }, { "warningType" : { "$ne" : 4 } }], "$or" : [{ "studentName" : { "$regex" : "小", "$options" : "" } }, { "teacherName" : { "$regex" : "小", "$options" : "" } }] })
{ "schoolId" : "f11c8ea12f457dbc19c768a8bb6357f8", "batchId" : "", "$and" : [{ "warningType" : { "$gte" : 1 } }, { "warningType" : { "$ne" : 4 } }], "$or" : [{ "studentName" : { "$regex" : "小", "$options" : "" } }, { "teacherName" : { "$regex" : "小", "$options" : "" } }] } fields: Document{{}} for class: class com.zhangtao.moguding.practiceservice.entity.GxyWarnEntity in collection: gxyWarnEntity
2019-10-15 09:52:17.819 DEBUG 13028 --- [io-9020-exec-15] o.s.data.mongodb.core.MongoTemplate : Executing count: { "schoolId" : "f11c8ea12f457dbc19c768a8bb6357f8", "batchId" : "", "$and" : [{ "warningType" : { "$gte" : 1 } }, { "warningType" : { "$ne" : 4 } }], "$or" : [{ "studentName" : { "$regex" : "小", "$options" : "" } }, { "teacherName" : { "$regex" : "小", "$options" : "" } }] } in collection: gxyWarnEntity
public List<GxyWarnEntity> selectWarnPage(GxyWarnEntity gxyWarnEntity){
Criteria cri =Criteria.where("schoolId").is(gxyWarnEntity.getSchoolId());
if(gxyWarnEntity.getBatchId()!=null) {
cri.and("batchId").is(gxyWarnEntity.getBatchId());
}
if(gxyWarnEntity.getDepId()!=null){
cri.and("depId").is(gxyWarnEntity.getDepId());
}
if(gxyWarnEntity.getWarningType()!=null && gxyWarnEntity.getWarningType() != EnumUnsignType.UNSIGNONE.getType()){
cri.andOperator(
Criteria.where("warningType").gte(gxyWarnEntity.getWarningType()),
Criteria.where("warningType").ne(EnumUnsignType.UNSIGNONE.getType())
);
}
if(gxyWarnEntity.getStudentName()!=null){
cri.orOperator(Criteria.where("studentName").regex(gxyWarnEntity.getStudentName()),
Criteria.where("teacherName").regex(gxyWarnEntity.getStudentName())
//,Criteria.where("classTeacherName").regex(gxyWarnEntity.getStudentName())
);
}
Query query = new Query(cri);
if (gxyWarnEntity.getCurrPage() != null && gxyWarnEntity.getPageSize() != null) {
query.skip((gxyWarnEntity.getCurrPage()-1)*gxyWarnEntity.getPageSize())
.limit(gxyWarnEntity.getPageSize());
}
return template.find(query, GxyWarnEntity.class);
}
mongodb and 和 or 查询的更多相关文章
- NodeJs操作MongoDB之多表查询($lookup)与常见问题
NodeJs操作MongoDB之多表查询($lookup)与常见问题 一,方法介绍 aggregate()方法来对数据进行聚合操作.aggregate()方法的语法如下 1 aggregate(ope ...
- mongoDB的文档查询
1.简单查询: find() 方法以非结构化的方式来显示所有文档. 语法 MongoDB 查询数据的语法格式如下: collection是集合名字,注意应该是当前数据库的集合,collect ...
- 7. java操作MongoDB,采用_id查询
转自:https://www.2cto.com/database/201704/633262.html mongodb命令行_id查询方法 直接用ObjectId() db.getCollection ...
- MongoDB文档(二)--查询
(一)查询文档 查询文档可以使用以下方法 # 以非结构化的方式显示所有的文档 db.<collectionName>.find(document) # 以结构化的方式显示所有文档 db.& ...
- MongoDB学习笔记六—查询下
查询内嵌文档 数据准备 > db.blog.find().pretty() { "_id" : ObjectId("585694e4c5b0525a48a441b5 ...
- MongoDB学习笔记五—查询上
数据准备 { , "goods_name" : "KD876", "createTime" : ISODate("2016-12- ...
- MongoDB 文档的查询和插入操作
MongoDB是文档型数据库,有一些专门的术语,和关系型DB相似,但也有差异,例如,Collection类似于关系型DB的Table,document类似于row,key/value pair类似于c ...
- Mongodb profile(慢查询日志)
在MySQL中,慢查询日志是经常作为我们优化数据库的依据,那在MongoDB中是否有类似的功能呢?答案是肯定的,那就是MongoDB Database Profiler.所以MongoDB 不仅有,而 ...
- MongoDB中的高级查询(二)
$mod取模运算 查询index对5取模运算等于1的数据. $not $not是元条件句,即可以用在任何其他条件之上.查询index对5取模运算不等于1的数据. $exists判断字段是否存在 查询出 ...
- MongoDB学习 (六):查询
本文地址:http://www.cnblogs.com/egger/archive/2013/06/14/3135847.html 欢迎转载 ,请保留此链接๑•́ ₃•̀๑! 本文将介绍操作符的使用 ...
随机推荐
- 使用Python进行3DES加密-pyDes
pyDes.py源码 ############################################################################# # Documenta ...
- TCP的半连接
T C P提供了连接的一端在结束它的发送后还能接收来自另一端数据的能力.这就是所谓下载的半关闭.正如我们早些时候提到的只有很少的应用程序使用它.为了使用这个特性,编程接口必须为应用程序提供一种方式来说 ...
- httprunner---->最最基础小白笔记
1.安装httprunner pip install httprunner 2.cmd 执行hrun --startproject Api_api 出现了: 3.Fiddler抓包后 ...
- v-model原理解析
vue中v-model可以实现数据的双向绑定,但是为什么这个指令就可以实现数据的双向绑定呢? 其实v-model是vue的一个语法糖.即利用v-model绑定数据后,既绑定了数据,又添加了一个inpu ...
- mysql group_concat长度限制
group_concat函数有长度限制 查找当前数据库长度 show variables like 'group_concat_max_len' 设置当前session的group_concat长度, ...
- EF非常见错误:EXECUTE 后的事务计数指示 BEGIN 和 COMMIT 语句的数目不匹配
EF非常见错误:EXECUTE 后的事务计数指示 BEGIN 和 COMMIT 语句的数目不匹配 问题原因: 两个表A\B之间存在外键关系,当插入表A的时候,A的外键B在B表中不存在可以引起这个问题: ...
- AtCoder Beginner Contest 148
ABC 148 第一次打abc,记录一下 Task Name Time Limit Memory Limit A Round One 2 sec 1024 MB B Strings with the ...
- 004_FreeRTOS创建与删除任务
(一)创建与删除任务函数 (二)上面的四个函数目前只用动态创建任务和删除任务 (三)动态创建任务 函数 xTaxkCreate() 1. 宏 configSUPPORT_DYNAMIC_ALLOCAT ...
- centos安装JDK、Tomcat、mysql
1.下载 jdk-8u131-linux-x64.tar.gz 下载地址: https://pan.baidu.com/s/1o8LW9eE 密码: miva 2.下载 apache-tomcat-8 ...
- CF922D Robot Vacuum Cleaner 贪心+排序
正确的贪心方法:按照比例排序. code: #include <bits/stdc++.h> #define N 200000 #define ll long long #define s ...