Springboot MongoDB JPA Common method collation

Source: Internet
Author: User
Tags mongodb

Official Document Https://docs.spring.io/spring-data/data-mongodb/docs/current/reference/html/index.html

Inquire:

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

Mongotemple Query and modification

@Autowired
Mongotemplate mongotemp;

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);

Native Mountain Query statement query

@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…?]}}

IsNotNull,NotNull

findByFirstnameNotNull()

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

IsNull,Null

findByFirstnameNull()

{"firstname" : null}

LikeStartingWith,EndingWith

findByFirstnameLike(String name)

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

NotLike,IsNotLike

findByFirstnameNotLike(String name)

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

ContainingOn String

findByFirstnameContaining(String name)

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

NotContainingOn String

findByFirstnameNotContaining(String name)

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

ContainingOn Collection

findByAddressesContaining(Address address)

{"addresses" : { "$in" : address}}

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

Keyword can be linked with and methods.

For example:

list<discountcode> FindFirst5byActivityidinandendtimeafterandStatus( List<objectid> Activityids, Date endtime,string status);

Delete:

List <Person> deleteByLastname(String lastname);

Long deletePersonByLastname(String lastname);

Springboot MongoDB JPA Common method collation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.