Having trouble with Paging

I’ve already passed the pytest -m paging
but when I open the web browser, the status looks like this:

Could somebody tell me what’s wrong?


It means you didn’t pass the integration test. The unit test is written in python, but integration test is a javascript file.

am also getting error in passing the Paging Ticket.

Confused on the area to modify as all i did doesn’t work.

total_num_movies = 0
if page == 0:
total_num_movies = db.movies.count_documents(query)

if pages == 5:

movies = cursor.limit(movies_per_page).skip(2)

return (list(movies), total_num_movies)

I have tried all these but not working.

Can you help to direct me on the area to modify. Or should I go and take python programming course first? before coming back. But am a DBA.
I will appreciate your assistance.


1 Like

Think of it like this, if page is 0 you want all the movies returned (to the amount specified in the limit) and you don’t want to skip any. So, your skip parameter should take that into account. If you are on the next page, you will want to skip those movies on the previous page, next page after that you would want to skip the movies on the first page and second page. Essentially, the amount you want to skip would be the product of the page number and the movies per page. Hope that makes sense. It helps me learn to type out my thought process :slight_smile:


@Richard_42461 @PaulNewman

We tried to author the course so that deep knowledge of python isn’t required. Sorry this is giving you issues.

As @cimes01 says, paging can be thought of as the product of desired skip amount and number of items you want.

As an example, let’s imagine how Google might implement paging. Say we search for MongoDB and get back a million results. By default, we are shown 20 results per page. What if we want results beginning with result 80? What “page” would that be?

If the first page is page 0 and results per page is 20 (so items 0-19), and the second page is page 1 with 20 results (20-39). We can start to see a pattern emerge.

Results Shown = Skip (Results per page * page requested). Let’s see if that works.

0 = Skip(20 * 0) :white_check_mark:
20 = Skip(20 * 1) :white_check_mark:

What about page 100?

1980 = Skip(20 * 99) :white_check_mark:

Does this explanation help?

1 Like

Hi, Paulnewman,

You could read sample function get_movies_faceted(filters, page, movies_per_page) carefully, especially line 112 and 113. The code explain itself. And handshake, we both are DBAs.

Thanks for your explanation.
Actually, I know how to compute the result.
I’ve written code like this:

But it still doesn’t work.

I just use “movies = cursor.skip(movies_per_page * page).limit(movies_per_page)” and works fine. My test return a code validation em UI.

mod edit Please don’t post full solutions @bigworks. Learning happens at the edge of comfort. Copying and pasting a solution yields nothing.


Are we supposed to be on “get_movies_faceted” already?

Paging ticket is in get_movies. Part of get_movies_faceted also implements the paging function.

Ok, I stand corrected. :slight_smile:

could you explain this integration test please? I’m having the same problem. passed paging test but getting error on status page. Thanks.

Please DM me with your implementation. If it passes the unit test it should pass the integration test so I’d like to fix this!


What about the (total_num_movies) variable? I see the document count method is only called if page == 0. Do we only want to perform this count (once initially) on the first page (page==0). Perhaps for performance reasons?


Thank you. the error was resolved.