spring mongodb查询
MongoRepository 查询条件
| Keyword | Sample | Logical result |
|---|---|---|
After |
findByBirthdateAfter(Date date) |
{"birthdate" : {"$gt" : date}} |
GreaterThan |
findByAgeGreaterThan(int age) |
{"age" : {"$gt" : age}} |
GreaterThanEqual |
findByAgeGreaterThanEqual(int age) |
{"age" : {"$gte" : age}} |
Before |
findByBirthdateBefore(Date date) |
{"birthdate" : {"$lt" : date}} |
LessThan |
findByAgeLessThan(int age) |
{"age" : {"$lt" : age}} |
LessThanEqual |
findByAgeLessThanEqual(int age) |
{"age" : {"$lte" : age}} |
Between |
findByAgeBetween(int from, int to) |
{"age" : {"$gt" : from, "$lt" : to}} |
In |
findByAgeIn(Collection ages) |
{"age" : {"$in" : [ages…]}} |
NotIn |
findByAgeNotIn(Collection ages) |
{"age" : {"$nin" : [ages…]}} |
IsNotNull, NotNull |
findByFirstnameNotNull() |
{"firstname" : {"$ne" : null}} |
IsNull, Null |
findByFirstnameNull() |
{"firstname" : null} |
Like, StartingWith, EndingWith |
findByFirstnameLike(String name) |
{"firstname" : name} (name as regex) |
NotLike, IsNotLike |
findByFirstnameNotLike(String name) |
{"firstname" : { "$not" : name }} (name as regex) |
Containing on String |
findByFirstnameContaining(String name) |
{"firstname" : name} (name as regex) |
NotContaining on String |
findByFirstnameNotContaining(String name) |
{"firstname" : { "$not" : name}} (name as regex) |
Containing on Collection |
findByAddressesContaining(Address address) |
{"addresses" : { "$in" : address}} |
NotContaining on Collection |
findByAddressesNotContaining(Address address) |
{"addresses" : { "$not" : { "$in" : address}}} |
Regex |
findByFirstnameRegex(String firstname) |
{"firstname" : {"$regex" : firstname }} |
(No keyword) |
findByFirstname(String name) |
{"firstname" : name} |
Not |
findByFirstnameNot(String name) |
{"firstname" : {"$ne" : name}} |
Near |
findByLocationNear(Point point) |
{"location" : {"$near" : [x,y]}} |
Near |
findByLocationNear(Point point, Distance max) |
{"location" : {"$near" : [x,y], "$maxDistance" : max}} |
Near |
findByLocationNear(Point point, Distance min, Distance max) |
{"location" : {"$near" : [x,y], "$minDistance" : min, "$maxDistance" : max}} |
Within |
findByLocationWithin(Circle circle) |
{"location" : {"$geoWithin" : {"$center" : [ [x, y], distance]}}} |
Within |
findByLocationWithin(Box box) |
{"location" : {"$geoWithin" : {"$box" : [ [x1, y1], x2, y2]}}} |
IsTrue, True |
findByActiveIsTrue() |
{"active" : true} |
IsFalse, False |
findByActiveIsFalse() |
{"active" : false} |
Exists |
findByLocationExists(boolean exists) |
{"location" : {"$exists" : exists }} |
spring mongodb查询的更多相关文章
- spring Mongodb查询索引报错 java.lang.NumberFormatException: empty String
最近事情比较多,本篇文章算是把遇到的问题杂糅到一起了. 背景:笔者最近在写一个mongo查询小程序,由于建立索引时字段名用大写,而查询的时候用小写. 代码如下: db.getCollection(&q ...
- Spring Boot MongoDB 查询操作 (BasicQuery ,BSON)
MongoDB 查询有四种方式:Query,TextQuery,BasicQuery 和 Bson ,网上太多关于 Query 的查询方式,本文只记录 BasicQuery和Bson 的方式,Basi ...
- Spring MVC + Spring MongoDB + Querydsl 通过maven整合实例
效果图 一共3个页面:注册页,欢迎页,用户列表页 很简单的例子,主要是为了把流程走通,没有各种验证. 注册页: 欢迎页: 用户列表页: 源码地址 https://github.com/lemonbar ...
- MongoDB查询转对象是出错Element '_id' does not match any field or property of class
MongoDB查询转对象是出错Element '_id' does not match any field or property of class 解决方法: 1.在实体类加:[BsonIgno ...
- spring jdbc 查询结果返回对象、对象列表
首先,需要了解spring jdbc查询时,有三种回调方式来处理查询的结果集.可以参考 使用spring的JdbcTemplate进行查询的三种回调方式的比较,写得还不错. 1.返回对象(queryF ...
- MongoDB查询操作限制返回字段的方法
这篇文章主要介绍了MongoDB查询操作限制返回字段的方法,需要的朋友可以参考下 映射(projection )声明用来限制所有查询匹配文档的返回字段.projection以文档的形式列举结果集中 ...
- mongodb查询文档
说到查询,我们一般就想起了关系型数据库的查询了,比如:order by(排序).limit(分页).范围查询(大于某个值,小于某个值..,in查询,on查询,like查询等待很多),同样mongodb ...
- [转]mongodb 查询条件:关系运算符"$lt", "$lte", "$gt", "$gte", "$ne" 逻辑运算符"$and“, "$or“, "$nor“
mongodb 查询条件 这节来说说mongodb条件操作符,"$lt", "$lte", "$gt", "$gte" ...
- Mongodb查询的用法,备注防止忘记
最近在用这个东西,为防止忘记,记下来. 集合简单查询方法 mongodb语法:db.collection.find() //collection就是集合的名称,这个可以自己进行创建. 对比sql语句 ...
随机推荐
- 一次mysql调优过程
由于经常被抓取文章内容,在此附上博客文章网址:,偶尔会更新某些出错的数据或文字,建议到我博客地址 : --> 点击这里 前几天进行了一个数据库查询,比较缓慢,便查询了一下,在这里记录一下,方便 ...
- JavaWeb -jsp文件和内置对象的解析
jsp文件和内置对象的解析 对page解析 JSP九大内置对象(自带,无需new) 1 out:输出对象 2 request:请求对象,存储“客户端像服务端发送的请求信息” 3 response:响应 ...
- 使用X-Pack插件来进行权限控制
1.为elasticsearch安装X-Pack插件.进入 elasticsearch根目录,执行: bin/elasticsearch-plugin install x-pack杀掉进程,重启es, ...
- [ActionScript 3.0] 模拟win7彩色气泡屏保效果
主文件: package { import com.views.BubbleView; import com.views.ColorfulBubble; import flash.display.Sp ...
- c语言求方阵的行列式、伴随矩阵算法
#include<stdio.h> #include<math.h> #define N 100 //N比输入的阶数大即可 int main() { int n,a[N][ ...
- EDEM 2018 + Fluent 19.0耦合
具体步骤参考流沙的文章即可,如果python版本较高,可能有个地方需要小小的改动一下: tools文件夹下的compile_lib_edem_coupling.py文件中,导入模块有个地方需要修改 其 ...
- (转)Mysql主从复制搭建及详解
http://www.cnblogs.com/kevingrace/p/6256603.html---------Mysql主从同步(1)-主从/主主环境部署梳理 原文:http://blog.csd ...
- javascript中的抽象相等==与严格相等===
1.数据类型:String,Number,Boolean,Object,Null,Undefined 2.抽象相等:x==y A.两者数据类型相同:typeof x == typeof y a.Str ...
- echart 时间轴、以及y轴值过大但是变化不大显示感觉不出变化的问题+弹出框拖动div事件
1.时间轴 echart 提供了一种图表,如果x轴是一个时间范围,并且是连续的,如果用传统的数据驱动会很慢,所以用时间轴的方式 function initCurve(_data){ var resul ...
- Spark Launcher