Ticket: Text and Subfield Search

First of all, I’d like to say that I’m learning a lot from this course.

I have a question that is related to the use of try/catch and query.

In the previous ticket, the one that we need to implement the getMoviesByCountry method we use a try/catch approach.

let results
try {
results = await movies.find(
{countries : {in: countries}}, {projection: {title: 1}} ); console.log(results) } catch (e) { console.error(`Unable to issue find command, {e}`)
return
}
return results.toArray()

However in this ticket we use a simple query.

const searchGenre = Array.isArray(genre) ? genre : genre.split(", ")
const query = {genres: {$in: searchGenre}}
const project = {}
const sort = DEFAULT_SORT
return { query, project, sort }

Why is that?

in the getMoviesByCountry function, you try to actually find movies with the find() method.

in the searchGenre function - you just building the query, project, and sort objects for the getMovies function to use. the getMovies function is using try/catch.

1 Like