Find entity with latest date using Spring Data with MongoDB

Viewed 9913

Given next object structure:

class Foo {
  @Id
  String id;
  LocalDate date;
  ...
}

We store these objects in MongoDB. Is there any possibility to get entity with the latest date via MongoRepository like in the next example?

interface FooRepository extends MongoRepository<Foo, String> {
    @Query(???)
    Foo getByLatestDate(LocalDate date);
}
1 Answers
Related