mongdb查询笔记

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值