Finding Max and Min values from a MongoDB Repository in Spring Boot

howells699 :

Is it possible to get the max and min values of a specific field within a repository within Spring Boot? If so, how do you do it?

I understand it is very easy using Mongo Shell.

https://docs.mongodb.com/manual/reference/operator/meta/max/

I've been investigating for a while now and still haven't come up with a solution.

Thanks in advance.

howells699 :

Found it.

public interface OrderRepository extends MongoRepository<Order,String> {

// Find MAX Value

Order findTopByOrderByOrderDateDesc();

// Find MIN Value

Order findTopByOrderByOrderDateAsc();

}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=80598&siteId=1