Unable to get data from db for search by country - Ticket Projection

static async getMoviesByCountry(countries) {
/**
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.
*/

let cursor
try {
  // TODO Ticket: Projection
  // Find movies matching the "countries" list, but only return the title
  // and _id. Do not put a limit in your own implementation, the limit
  // here is only included to avoid sending 46000 documents down the
  // wire.
  cursor = await movies.find({country:{$all: countries}},{projection:{title:1}}).limit(1)
} catch (e) {
  console.error(`Unable to issue find command, ${e}`)
  return []
}

return cursor.toArray()

}

Hi @Kanika /@nathan.leniz
Even i am facing similar issue , though when i run the same condition queries in mongo shell i get correct results , but when i run the test case it says expected : 2 received 1 &
Expected value to equal:
2788
Received:
1
Mod Edit - Please don’t paste screenshots of implementation queries

Your projection is wrong for the js driver.

See Ticket: Projection Test for 3 entries not passing

do you remove limit(1)?

// TODO Ticket: Projection
// Find movies matching the “countries” list, but only return the title
// and _id. Do not put a limit in your own implementation, the limit
// here is only included to avoid sending 46000 documents down the
// wire.

1 Like

Thank you @steevej-1495 , it solved my problem.

Thank you @imareo it solved the issue/

cursor = await movies.find({ country: { $all: countries } }, { project: { title: 1 } })
Tried Removing limit. it didnt solved m problem

try read Remember that … in your post

@nathan.leniz Sure .