Ticket : Projection (Need to specify uri/client info?)

Hi,

I have no problem to test get_movies_by_country(countries) using jupyter providing uri, client… info like shown in the lecture and providing the syntax within the movies.find() query, the values of the len(result) for the two test cases returned are same as the assert values in test_projection.py but i am not using the ‘db’ within the return list syntax as given in the db.py file.

Below is how I tested and it worked in Jupyter:-

def get_movies_by_country(countries):
connection info from lecture (uri, client, mflix, movies)
return list(movies.find(myquery)
return dumps(cursor, indent=2)
result = get_movies_by_country([‘xxx’])
print(len(result)) # returned values are correct for the countries specified in test_projection.py

But when I copied the above connection info and return list syntax above to the get_movies_by_country(countries) in db.py, it doesn’t work.

Wonder…
Do we need to supply uri, client… info to either db.py or test_projection.py script or should it automatically pick up from the .ini file we modified earlier?
Do we have to use the db from db = LocalProxy(get_db) in db.py file ?
Do we just need to modify the line by supplying the query within the find() for the return list(db.movies.find()) ?

Thanks,

1 Like

It is all picked up from the .ini file.

We only have to adjust the Python commands so the right queries are passed to MongoDB.

Thank you! For some reasons, it works now.

Hi user @wini_mongo.

Please, finally you only modified “return list(db.movies.find())” line?

I modified only that line (my example):
img01

But when run “pytest -m projection” and “python run.py” in the http://localhost:5000/status I see a error:
img02

Please help me, Should I change anything else?

First, please do not post potential answers even when they are wrong.

Second, fyi the document field countries is an array/list and so is the python variable countries. This means you have to use an array operator. For more info refer to https://docs.mongodb.com/manual/reference/operator/query/

1 Like

Thanks for the observation, I’ll be careful next time.
Thanks also for the comment, I managed to finish the exercise :smile: .