M220: Projection not working

Same error as Jali20009 Here is my query

def get_movies_by_country(countries):
“”"
Finds and returns movies by country.
Returns a list of dictionaries, each dictionary contains a title and an _id.
“”"
try:

    """
    Ticket: Projection

    Write a query that matches movies with the countries in the "countries"
    list, but only returns the title and _id of each movie.

    Remember that in MongoDB, the $in operator can be used with a list to
    match one or more values of a specific field.
    """

    # TODO: Projection
    # Find movies matching the "countries" list, but only return the title
    # and _id. Do not include a limit in your own implementation, it is
    # included here to avoid sending 46000 documents down the wire.
    return list(db.movies.find({ "countries": {"$in": [countries]} }, { "title": 1 }))

except Exception as e:
    return e

What is wrong with return list(db.movies.find({ “countries”: {"$in": [countries]} }, { “title”: 1 }))

Thank you
Meir

Hi @meir_ncfree

Please don’t share code in the forums explicitly, if you want to share code please do so using the direct mail/1:1 mailing/messaging functionality included in the Discourse forums.

In answer to your question, I’ll don’t believe you need to create an array of the variable “countries” which I believe is sent to the function in the correct format.

Kindest regards,

10:15 AM (14 minutes ago)
Hi Eoin, Sorry about that I will follow the 1:1 going forward. Thank you for the advice That solved it.