4. Querying Documents
Activity 4.01: Finding Movies by Genre and Paginating Results
Solution:
The most important part of the findMoviesByGenre
function is the underlying MongoDB query. You will take a step-by-step approach to solving the problem, starting with creating the query on a mongo shell. Once the query has been prepared, you will wrap it into a function:
- Create a query to filter results by
genre
. For this activity, we are using theAction
genre:Â Â Â Â Â Â db.movies.find( Â Â Â Â Â Â Â Â Â Â {"genres" : "Action"} Â Â Â Â Â Â )
- The requirement is to return only the titles of the movies. For this, add a projection to project only the
title
field and exclude the rest, including_id
:Â Â Â Â Â Â db.movies.find( Â Â Â Â Â Â Â Â Â Â {"genres" : "Action"}, Â Â Â ...