Projection validation code not getting

I write this code

list(db.movies.find({ “countries” : { “$in” : countries } }, { “title” : 1 } ))
test case passed

In console i am getting this


in web page i am getting this

please let me know what is wrong i did in it

Thanks in advance for all of you

Make sure you return the list of movies. If still unresolved, please share the code for function “get_movies_by_country”.


I used return the list
return list(db.movies.find({ “countries” : { “$in” : countries } }, { “title” : 1 } ))
but output still same

Please share the code for the whole function.


Hi Kanika,

Please find my function code

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.

    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

Hi @rajesh_50804,

Code seems right!

Can you please check your dataset loaded in your cluster and verify that there are total: 23539 documents in movies collection?


Yeah it’s loaded correctly total: 23539 documents in movies collection. I checked same code in compass it’s working perfectly there.

Anyway no issue now the lab completion time limit is over. I will check next time once i will start this course fresh.

Thanks for your quick responses and support.