Can someone please explain what is the difference between these query 1 & 2 and why query number 1 passes all tests and query 2 doesnt?

I am currently on chapter 1 of m220js
i was on this challenge in moviesDAO.js file and had this doubt . kindly clarify it .

  1. cursor = await movies.find({countries : {"$in" : countries}}).project({title : 1}) (this one passes )

  2. cursor = await movies.find({countries : {"$in" : countries}},{title : 1}) (this one doesnt )

Hi @pratik_giri and welcome in the MongoDB Community :muscle: !

The find() second parameter isn’t the projection like the find() function in mongosh.

Here is the doc to the find() in Node.js and the project which is a function applied on a cursor which is returned by the find().

So the second one isn’t respecting the Node.js Driver API.

Cheers,
Maxime.

Thank you for clarifying my doubt

1 Like