官方文档https://docs.spring.io/spring-data/data-mongodb/docs/current/reference/html/index.html

查询:

***************************************************************************

mongoTemple查询和修改

@Autowired
MongoTemplate mongoTemp;

Criteria criteria = Criteria.where("name").regex("www").andOperator(Criteria.where("creatTime").gte(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2018-06-20 21:48:54")));
mongoTemp.find(new Query(criteria), Movie.class);

**************************************************************************

List<User> findByName(String name);

List<User> findByNameAndAge(String name,String age);

long countByName(String name);

原生查询语句

@Query(value="{'$and':[{'name':{'$regex':?0}}]}")
public List<Movie> findByName(String name);

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…​]}}

IsNotNullNotNull

findByFirstnameNotNull()

{"firstname" : {"$ne" : null}}

IsNullNull

findByFirstnameNull()

{"firstname" : null}

LikeStartingWithEndingWith

findByFirstnameLike(String name)

{"firstname" : name} (name as regex)

NotLikeIsNotLike

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]}}}

IsTrueTrue

findByActiveIsTrue()

{"active" : true}

IsFalseFalse

findByActiveIsFalse()

{"active" : false}

Exists

findByLocationExists(boolean exists)

{"location" : {"$exists" : exists }}

KeyWord可以用and方法连起来。

例如:

List<DiscountCode> findFirst5ByActivityIdInAndEndTimeAfterAndStatus(List<ObjectId> activityIds, Date endTime,String status);

删除:

List <Person> deleteByLastname(String lastname);

Long deletePersonByLastname(String lastname);

springboot mongodb jpa常用方法整理的更多相关文章

  1. springboot整合JPA(简单整理,待续---)

    整合步骤 引入依赖: <dependencies> <dependency> <groupId>org.springframework.boot</group ...

  2. Springboot+Atomikos+Jpa+Mysql实现JTA分布式事务

    1 前言 之前整理了一个spring+jotm实现的分布式事务实现,但是听说spring3.X后不再支持jotm了,jotm也有好几年没更新了,所以今天整理springboot+Atomikos+jp ...

  3. 【极简版】SpringBoot+SpringData JPA 管理系统

    前言 只有光头才能变强. 文本已收录至我的GitHub仓库,欢迎Star:https://github.com/ZhongFuCheng3y/3y 在上一篇中已经讲解了如何从零搭建一个SpringBo ...

  4. 带你搭一个SpringBoot+SpringData JPA的环境

    前言 只有光头才能变强. 文本已收录至我的GitHub仓库,欢迎Star:https://github.com/ZhongFuCheng3y/3y 不知道大家对SpringBoot和Spring Da ...

  5. 二、springboot使用jpa

    花了几天时间,好好看了看springboot的jpa部分,总结了常用的形式. 1.通过STS工具添加jpa的依赖项 要连mysql,测试的时候需要web,顺便添加了lombok不写set和get方法了 ...

  6. Python 部分系统类的常用方法整理

    下面是常用的几个系统类的常用方法整理: list: 列表[1, 2,...] set: 集合,无重复元素{1, 2,...} str: 字符串 dict: 字典{a:'a', b:'b',...} T ...

  7. Springboot+MyBatis+JPA集成

      1.前言 Springboot最近可谓是非常的火,本人也在项目中尝到了甜头.之前一直使用Springboot+JPA,用了一段时间发现JPA不是太灵活,也有可能是我不精通JPA,总之为了多学学Sp ...

  8. 【第十二章】 springboot + mongodb(复杂查询)

    简单查询:使用自定义的XxxRepository接口即可.(见 第十一章 springboot + mongodb(简单查询)) 复杂查询:使用MongoTemplate以及一些查询条件构建类(Bas ...

  9. 第12章—使用NoSQL数据库—使用MongoDB+Jpa操作数据库

    使用MongoDB+Jpa操作数据库 SpringData还提供了对多种NoSQL数据库的支持,包括MongoDB;neo4j和redis.他不仅支持自动化的repository,还支持基于模板的数据 ...

随机推荐

  1. vue-loader+webpack配置项目流程

    前提:安装了node.js与npm 1.建立一个npm项目 新建项目文件夹,打开终端,将路径移动至此文件夹,初始化输入 npm init 按照提示输入项目名称,描述,作者等信息(可回车跳过) 成功创建 ...

  2. Mybatis 实体类使用@Accessors(chain = true)注解时,对应的mapper xml 报错

    去掉这个注解就行了 应该是 mybatis 会调用实体类的 getter  setter 方法, 返回值可能会有所影响

  3. JS基础_变量提升和函数提升

    1.在函数中,不使用var声明的变量都会变为全局变量 function fun(){ d=10; //window.d=10; }; console.log(10);//10 2.定义形参就相当于在函 ...

  4. RequestsLibrary接口测试

    RequestsLibrary常用的关键字 关  键  字 描   述 Create Session 创建HTTP会话 Get Request 采用get方式请求 Post Request 采用Pos ...

  5. jQuery获取元素值以及设置元素值总结

    html(): 1:用户获取元素内的HTML内容,如果元素包含子标签,会以整体的形式返回 2:只获取第一个元素的内容 3:只获取普通元素的内容,表单元素内容无法获取 html(val): 1:用来设置 ...

  6. AXIS 1.4 自定义序列化/反序列化类

    axis1.4的CalendarDeserializer 使用的时区是GMT,导致日期显示不准确 private static SimpleDateFormat zulu = new SimpleDa ...

  7. tensorflow读取图片案例

    1.知识点 """ 1.图片读取流程与API: 1.构造图片文件队列 文件队列API: a)tf.train.string_input_producer(string_t ...

  8. 使用sql developer 导出Oracle数据库中的表结构

    MS SQLServer的客户端工具做的的确比较好,直接右键,导出数据库就OK了,而且MS的客户端导出的是xxx.dbf文件,直接附加到别的数据库上就OK了 Oracle的sql developer就 ...

  9. SQL学习(四)Where语句中的各种匹配方式

    在where语句中,我们需要制定各种条件,条件的各种组合需要用到不同的关键字 一.单条件 如:select * from ticket where name='测试' 二.多条件 1.和(and) 如 ...

  10. Jmeter接口测试图文示例

    Jmeter接口测试图文示例 以getObjectByCode接口为例,用jmeter2.13来进行接口测试. 测试前准备: 测试工具及版本:jmeter 2.13 r1665067(须包含__MD5 ...