Chapter 2: User-Facing Backend - Ticket: Paging

I’ve implemented the paging code inside the getMoviesByGenre method, but, when I update the status page, I do not get the exercise code. The pagination works fine and the test (testPagingByGenre) is ok. I don’t know what might be wrong, maybe I have some difficulty in understanding, because, I know almost nothing of the English language.
Here is my code:

public List getMoviesByGenre(String sortKey, int limit, int skip, String… genres) {
// query filter
Bson castFilter = Filters.in(“genres”, genres);
// sort key
Bson sort = Sorts.descending(sortKey);
List movies = new ArrayList<>();

MongoCursor cursor = moviesCollection.find()
.filter(castFilter)
.skip(skip)
.limit(limit)
.sort(sort)
.iterator();

while (cursor.hasNext()){
movies.add(cursor.next());
}

return movies;

}

I appreciate any help, thank you.

Do you have any error messages when you try the status page?

The only error is: “Paging: Did not receive the proper response when paging by cast”

1 Like

Hi @Tarcisio_de_Paulo_Rosa_51215,

You might want to re-arrange the stages for find query. You may find the documentation useful:

https://docs.mongodb.com/manual/core/aggregation-pipeline-optimization/#project-skip-sequence-optimization

Let me know if it does not work.

Kanika

I followed his suggestion and proceeded to analyze the results step-by-step when I discovered that the ordering in the “getMoviesByCast” function was ascending. I changed to descending and everything worked fine.:grinning:
Thank you very much for your attention and your help.:pray:

1 Like