Ticket : Projection failure

Hi, I’m afraid that I di not understandthe problem to be resolved in the Ticket.
My suggestion was:

…Remember that in MongoDB, the $in operator can be used with a list to
match one or more values of a specific field.
*/
let filter = countries
let result = await movies.find({
countries: { $in: filter}},
{ projection: { title: 1}},
)
expect(result).not.toBeNull()
// and based on the projection we except the object to have 3 keys,
// title, year, and _id
let result = await movies.find({
countries: { $in: filter}},
{ projection: { title: 1, year:1}},
)
expect(Object.keys(result).length).toBe(3)
console.log(result)
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({
countries: { in: filter}}, { projection: { title: 1}}, ) } catch (e) { console.error(`Unable to issue find command, {e}`)
return [title,_id]
}

return cursor.toArray()

}

Answer was:

Determining test suites to run…Setup Mongo Connection
(node:8224) Warning: Accessing non-existent property ‘count’ of module exports inside circular dependency
(Use node --trace-warnings ... to show where the warning was created)
(node:8224) Warning: Accessing non-existent property ‘findOne’ of module exports inside circular dependency
(node:8224) Warning: Accessing non-existent property ‘remove’ of module exports inside circular dependency
(node:8224) Warning: Accessing non-existent property ‘updateOne’ of module exports inside circular dependency
(node:8224) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to MongoClient.connect.
Browserslist: caniuse-lite is outdated. Please run next command npm update
FAIL test/projection.test.js
● Test suite failed to run

SyntaxError: C:\Users\Dzheb\mflix-js\src\dao\moviesDAO.js: Identifier 'result' has already been declared (67:8)

  65 |     // and based on the projection we except the object to have 3 keys,
  66 |     // title, year, and _id
> 67 |     let result = await movies.find({
     |         ^
  68 |       countries: { $in: filter}},
  69 |       { projection: { title: 1, year:1}},
  70 |

  at Parser.raise (node_modules/@babel/parser/lib/index.js:6325:17)
  at ScopeHandler.checkRedeclarationInScope (node_modules/@babel/parser/lib/index.js:3759:12)
  at ScopeHandler.declareName (node_modules/@babel/parser/lib/index.js:3725:12)
  at Parser.checkLVal (node_modules/@babel/parser/lib/index.js:8021:22)
  at Parser.parseVarId (node_modules/@babel/parser/lib/index.js:10502:10)
  at Parser.parseVar (node_modules/@babel/parser/lib/index.js:10477:12)
  at Parser.parseVarStatement (node_modules/@babel/parser/lib/index.js:10299:10)
  at Parser.parseStatementContent (node_modules/@babel/parser/lib/index.js:9896:21)
  at Parser.parseStatement (node_modules/@babel/parser/lib/index.js:9829:17)
  at Parser.parseBlockOrModuleBlockBody (node_modules/@babel/parser/lib/index.js:10405:25)

Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 1.765s, estimated 3s
Ran all test suites matching /projection/i.
Teardown Mongo Connection
Jest did not exit one second after the test run has completed.

This usually means that there are asynchronous operations that weren’t stopped in your tests. Consider running Jest with --detectOpenHandles to troubleshoot this issue.
Could make your comment about this?
Regsrds
Boris

Now test is OK:
Browserslist: caniuse-lite is outdated. Please run next command npm update
console.log src/dao/moviesDAO.js:75
{ _id: 573a13eff29313caabdd7dca, title: ‘Sworn Virgin’, year: 2015 }

console.log src/dao/moviesDAO.js:75
{
_id: 573a1392f29313caabcd9d4f,
title: ‘I Was Born, But…’,
year: 1932
}

PASS test/projection.test.js
Projection
√ Can perform a country search for one country (327ms)
√ Can perform a country search for three countries (984ms)

Test Suites: 1 passed, 1 total
Tests: 2 passed, 2 total
Snapshots: 0 total
Time: 3.667s
Ran all test suites matching /projection/i.

BUT the ticket procedure still validating and do not give code…

Resolved finally thanks to reinstallation of the package.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.