M220J Ticket: Paging - one test failed but still able to run the application and got the code

HI all. I implemented solution for ticket Paging, all test cases run smoothly except the last test testPagingByGenre. This is the test result:

org.junit.ComparisonFailure: Expectedtitlefield does match: Please check your getMoviesByGenre() movies sort order. Expected :Only the Dead Actual :Wondrous Boccaccio

I know I finished the ticket and got the code, but leaving a test failing is not a good practice. The issue I met was never seen before so I hope you can help me with it. Thanks.

1 Like

Sending you a message to share the code.


I have the same problem. Looking through the forum I found several tickets with exactly the same problem closed without any resolution by @kanikasingla. It is not the wrong sort order, the sort order is descending as it was already in the code and described in the comment above the code.

movieDocs = dao.getMoviesByGenre(sortKey, 20, skip, genre);
            "Expected `title` field does match: Please check your " + "getMoviesByGenre() movies sort order.",
            "Only the Dead",

This is the part of the test that is failing. I debugged it and found out the item at index 1 is Only the Dead. Looks like the data changed. It’s quite a pity that a lot of developer spend hours trying to find out what’s wrong, asking in the forums for help when it looks like it’s the data that’s changed.

Hi @Anna_Ira_87296,

You are right, the dataset was updated few weeks ago and to help developers we added one global banner to notify the same.
It was fixed in a few days and we apologise for any inconvenience it may have caused.

I am glad you fixed the issue, let me know if we can help any further. :slight_smile:


1 Like

I loaded the sample data set on Sept 22, 2020 and the data was still wrong. :frowning: Took me a while to think I needed to come here.

@kanakasingla, can you please verify that the sample data set loadable from https://cloud.mongodb.com/ is correct? (Or fix the test code.)

Hi @Dan_Greening,

The dataset is fixed and the tests are updated in the Handouts, please re-download the handouts if you have downloaded them before. :slight_smile:


1 Like

Did this using the Dec 2020 version of the handout, seems like its still having the same issue?

1 Like

Hi @Wing_Ming_Sam,

I am sure this issue was fixed and updated in Dec 2020 handouts, can you please describe the issue and error you are getting?


Hi Everyone,

I’m having the same issue:
Expected :Only the Dead
Actual :Killing Jesus
I highly suggest that you change the test case. Actually you are testing on movies that have no tomatoes.viewer.numReviews field (i.e. the sorting key), which makes the order of the last documents (those without the sorting key) inconsistent.
You can fix this by testing on the first pages (e.g. the first document of the 10th page)


1 Like


When I run the following aggregation pipeline on sample_mflix.movies collection:

  {$match: { "tomatoes.viewer.numReviews" : { "$exists" : true }}},
  {$count: 'count'}

I get

{ "count" : 20573 }

by executing the pipeline

[{$group: {
  _id:{$gt:["$tomatoes.viewer.numReviews", null]},

I get two documents

{_id: false
count: 2957}

{_id: true
count: 20573}

implying that mongodb gives no guarantee about the order of the last 2957 documents if asked to sort by tomatoes.viewer.numReviews.
unfortunately, the test case is a movie without a tomatoes.viewer.numReviews. the pipeline:

[{$match: {
  title: 'Only the Dead'
}}, {$project: {
  title: 1,
  typeTVNR: {
   $type: '$tomatoes.viewer.numReviews'


_id: ObjectId("573a13eef29313caabdd62bf"),
title: "Only the Dead",
typeTVNR: "missing"

thus the inconsistency

I have exactly the same issue with you.
I’m using atlas with sample database loaded.
In my database, excution of the following command

db.movies.find({"genres": "History"}).sort({"tomatoes.viewer.numReviews":-1})

the 280th entry is " Killing Jesus" and the 276th entry is “Only the Dead”,Both movies have no tomatoes reviews. I think it’s an issue with the sort order.

1 Like

July 2022 and this issue still exists. You fail the test, but pass if you get your validation code.