博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mongdb查询笔记
阅读量:2198 次
发布时间:2019-05-02

本文共 2818 字,大约阅读时间需要 9 分钟。

10.3.1. Repository delete queries
The above keywords can be used in conjunction with 
delete…By
 or 
remove…By
 to create queries deleting matching documents.
Example 75. 
Delete…By
 Query
public interface PersonRepository extends MongoRepository<Person, String> { List <Person> deleteByLastname(String lastname); Long deletePersonByLastname(String lastname);}
Using return type 
List
 will retrieve and return all matching documents before actually deleting them. A numeric return type directly removes the matching documents returning the total number of documents removed.
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)
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 }}

转载地址:http://bdmub.baihongyu.com/

你可能感兴趣的文章
Intellij IDEA使用(五)—— Intellij IDEA在使用中的一些其他常用功能或常用配置收集
查看>>
Intellij IDEA使用(六)—— 使用Intellij IDEA创建Java项目并配置jar包
查看>>
Eclipse使用(十)—— 使用Eclipse创建简单的Maven Java项目
查看>>
Eclipse使用(十一)—— 使用Eclipse创建简单的Maven JavaWeb项目
查看>>
Intellij IDEA使用(十三)—— 在Intellij IDEA中配置Maven
查看>>
面试题 —— 关于main方法的十个面试题
查看>>
集成测试(一)—— 使用PHP页面请求Spring项目的Java接口数据
查看>>
使用Maven构建的简单的单模块SSM项目
查看>>
Intellij IDEA使用(十四)—— 在IDEA中创建包(package)的问题
查看>>
FastDFS集群架构配置搭建(转载)
查看>>
HTM+CSS实现立方体图片旋转展示效果
查看>>
FFmpeg 命令操作音视频
查看>>
问题:Opencv(3.1.0/3.4)找不到 /opencv2/gpu/gpu.hpp 问题
查看>>
目的:使用CUDA环境变量CUDA_VISIBLE_DEVICES来限定CUDA程序所能使用的GPU设备
查看>>
问题:Mysql中字段类型为text的值, java使用selectByExample查询为null
查看>>
程序员--学习之路--技巧
查看>>
解决问题之 MySQL慢查询日志设置
查看>>
contOS6 部署 lnmp、FTP、composer、ThinkPHP5、docker详细步骤
查看>>
TP5.1模板布局中遇到的坑,配置完不生效解决办法
查看>>
PHPstudy中遇到的坑No input file specified,以及传到linux环境下遇到的坑,模板文件不存在
查看>>