Hi Kushagra,
I’ve a problem with M220j Ticket: Paging.
I can’t pass the PagingTest.java
Here is the error:
org.junit.ComparisonFailure: Expected title
field does match: Please check your getMoviesByGenre() movies sort order.
Expected :Only the Dead
Actual :Wolf Hall
Looking at the parameter passed to the method by the test, I have tried this filter on compass.
{
filter: {
genres: {
$in: [
‘History’
]
}
},
sort: {
‘tomatoes.viewer.numReviews’: -1
},
skip: 980,
limit: 20
}
The result shows as the first movie “Wolf Hall”, while the Expected “Only the Dead” is the third.
Here below, my java code.
public List<Document> 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<Document> movies = new ArrayList<>();
// TODO > Ticket: Paging - implement the necessary cursor methods to support simple
// pagination like skip and limit in the code below
moviesCollection.find(castFilter).sort(sort).limit(limit).skip(skip).iterator()
.forEachRemaining(movies::add);
return movies;
}
Can you explain to me, what is wrong with it?
Thanks for the attention.