Projection Test: Key project not returning correct keys

cursor = await movies.find({“countries”: { “$in”: countries }}, {“title”:1, “_id”:1} ) should return just _id and title.

-I verified this by running db.movies.find({ “countries”: {$in:[“Kosovo”]}}, {“title”:1, “_id”:1} ).pretty() against the database and it returned 2 documents with 2 keys each of _id and title.

-However, the projection test always receives all the keys in the document.

-What might cause this?

Hi @Andrew_74578,

The projection works differently in Mongo shell and with Mongo Drivers like NodeJs. Please use project method when working with NodeJS library.

http://mongodb.github.io/node-mongodb-native/3.2/api/AggregationCursor.html#project

Let me know if it helps!

Kanika

Hi Andrew, I’m having the exact same problem. I saw Kanik’s response, but I’m still really confused by the docs provided, and googling aggregationCursor.project() is not turning up helpful resources. Did you ever figure this out, or find helpful resources?

Thanks

-Patrick

Hi Kanika,

I’m having the exact same problem, and I’m not finding the docs referenced helpful. Is there a spot where the project method is used, so I can understand by example?

The way andrew had it is exactly how it’s used in the sample docs: here’s from cursor-methods-agg-equivalents.spec

Hi @Patrick_N_A,

Apologies for the delay. Thanks for sharing your feedback and we hear you. :slight_smile: We will take this seriously and make relevant changes in our courseware.

In mflix-js/test/lessons/basic-reads.spec.js file, you can see projection if you want to run within find query:

let result = await movies.findOne(
      { cast: filter },
      { projection: { title: 1, year: 1 } },
    ) 

Can you try this for the projection ticket? Also, in projection ticket we are expecting 2 fields _id, title. :slight_smile:

cc @Shubham_Ranjan

Kanika

1 Like