在 Spring 引导中从 MongoDB 存储库中查找最大值和最小值

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

是否可以在 Spring Boot 中获取存储库中特定字段的最大值和最小值?如果是,你是怎么做到的?

我知道使用 Mongo Shell 非常容易。

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

我已经调查了一段时间了,但仍然没有想出解决办法。

提前致谢。

找到了。

public interface OrderRepository extends MongoRepository<Order,String> {

// Find MAX Value

Order findTopByOrderByOrderDateDesc();

// Find MIN Value

Order findTopByOrderByOrderDateAsc();

}