Ticket: Paging - Chapter 2

I haven’t been able to find the Movies.py module… where should I look or acquire this module to look at the Paging code?

The code you have to change is in db.py as indicated by:

Task

Modify the method get_movies in db.py to allow for paging. You can see how the page is parsed and sent in the api_search_movies method from movies.py.

Here lies my problem, I can’t find the movies.py file?

It says to change the file db.py, why do you want the file movies.py.

To see how the page is parsed and sent in the api_search_movies method from movies.py.
can you tell me where to find the module or email it to me?

(mflix) : steevej @ asus-laptop ; find . -name movies.py

./mflix/api/movies.py

Thanks… must be having a senior moment … taking this class plus and “R” online class…

i passed the paging test from command prompt but failing in mflix status pagep

1 Like

I am having the same problem. I ran all the functions in jupyter notebook too to verify and got the right results too.

I solved my issue…lets see your paging function in db.py

My function LIMIT is ignored. I have tried to hardcode numbers there, but I anyway got all result without any limit. What I did wrong?

Even in mongo shell, I have problems with LIMIT
limit

cursor.limit didn’t work for me, so I had to add limit and skip to cursors in if block

The way you use limit does not correspond to the described syntax.

You have to use:

cursor = db.movies.find(…).limit(10)

That’s why you get ‘query already executed’. Please consult the documentation:

https://docs.mongodb.com/manual/reference/method/db.collection.find/

In shell I have agreed, but what about Python? Why when I usemovies = cursor.limit(10) its ignored?

You gave us an output of something that does not work in JavaScript. I gave a JavaScript answer. As for python, the line seems fine it must be the code around it that is wrong. I have more or less the same line for this course and it works.

    total_num_movies = 0
    total_num_movies = db.movies.count_documents(query)
    """
    Ticket: Paging

    """
    movies = cursor.skip(page*movies_per_page).limit(movies_per_page)
    return (list(movies), total_num_movies)

I guess this must be a javascript issue, but i can’t tell what could be the problem

This is not JavaScript, this is python. We cannot help because we don’t know how you initialized cursor and cursor is the most important part of the puzzle.

@neha_30356

total_num_movies = 0
if page==0:
total_num_movies = db.movies.count_documents(query)
“”"
Ticket: Paging

"""
movies = cursor.skip(page*movies_per_page).limit(movies_per_page)
return (list(movies), total_num_movies)

i added if page==0 after total_num_movies=0
try this

1 Like

the total_num_movies = db.movies.count_documents(query) should be the if statement block code