简体   繁体   中英

Auto-Generated Spring data query for MongoDB: X most recent entries

I have been using this tutorial/guide to create auto-generated queries for a Mongo database. All but one of the methods I created have worked and I am wondering if anyone could give me some feedback on what I am doing wrong with this method:

List<DcrExecution> findDcrExecutionsByLimitOrderByExecutionTimeDesc(int num);

For now, I would like to avoid creating my own custom method. However, if that is the only option, then I will look into it. I want to find the X most recent dcrExecutions with X being a value the user chooses. So, I am new to spring, and I am unsure of the order in which to put the commands in the method so that Spring can generate a query method from it. I have tried some other variations of the method signature, for example:

List<DcrExecution> findDcrExecutionsOrderByExecutionTimeDescLimitBy(int num);

but this created the error:

No property descLimitBy found for type Date!

which is no where near what I was trying to achieve. I would like to create a method which will find the X most recent entries in the Mongo database. Order by will order them by date then desc will give me the most recent entries first. The limit or limit by will only retrive the top amount of entries specified by the parameter num. That is my thought process, anyways. Any help would be great!

Here is the full interface class:

public interface DcrExecutionRepo extends MongoRepository<DcrExecution, String> {
    List<DcrExecution> findDcrExecutionsByExecutionTimeAfter(Date date);

    //TODO: Fix
    //List<DcrExecution> findDcrExecutionsByLimitOrderByExecutionTimeDesc(int num);

    List<DcrExecution> findDcrExecutionsByFinishedIsFalse();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM