[Solved] Ticket mongoclient connection fail

npm test -t db-connection

> server@1.0.0 test /Users/choong/dev/mflix-js
> jest --passWithNoTests "db-connection"

Determining test suites to run...Setup Mongo Connection
(node:69971) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will b
e removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUni
fiedTopology: true } to MongoClient.connect.
Warning: no saslprep library specified. Passwords will not be sanitized
 FAIL  test/db-connection.test.js
    ✓ Can access MFlix data (14ms)
    ✓ Can retrieve a movie by id (8ms)
    ✕ Can retrieve first page of movies (66ms)

  ● Connection › Can retrieve first page of movies


    Expected value to equal:

      27 |     } = await MoviesDAO.getMovies()
      28 |     expect(firstPage.length).toEqual(20)
    > 29 |     expect(numMovies).toEqual(45993)
         |                       ^
      30 |   })
      31 | })
      32 | 

      at toEqual (test/db-connection.test.js:29:23)
      at tryCatch (node_modules/babel-runtime/node_modules/regenerator-runtime/runtime.js:62:40)
      at Generator.invoke [as _invoke] (node_modules/babel-runtime/node_modules/regenerator-runtime/runtime.js:296:22)
      at Generator.prototype.<computed> [as next] (node_modules/babel-runtime/node_modules/regenerator-runtime/runtime.js:114:21)
      at step (node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
      at node_modules/babel-runtime/helpers/asyncToGenerator.js:28:13

Test Suites: 1 failed, 1 total
Tests:       1 failed, 2 passed, 3 total
Snapshots:   0 total
Time:        0.572s, estimated 1s
Ran all test suites matching /db-connection/i.
Teardown Mongo Connection
npm ERR! Test failed.  See above for more details.

I did below 3 jobs.

  1. create Atlas cluster and import sample data.
  2. download zip and import sample data.
  3. clone repo and import sample data.

But… everty data count is 23539.
At compas, sample-mflix > movies collection document cnt is 23539.

Is the wrong data imported?
How can I import the right data?

Hi @Chunghee_13893,

Please make sure you have the latest zip directory for mflix-js as we have incorporated new changes.
You need to remove the current one and download new one m220/mflix-js.zip.

Let me know if the issue still persists.


Thx @Kanika
But… still failed.

sample-mflix collections movies document cnt is 23539.

This is mongo restore log

$ mongorestore --drop --gzip --uri mongodb://m220student:m220password@localhost:27017 data
2019-08-21T19:19:10.715+0900    preparing collections to restore from
2019-08-21T19:19:10.735+0900    reading metadata for sample-mflix.movies from data/sample-mflix/movies.metadata.json.gz
2019-08-21T19:19:10.759+0900    reading metadata for sample-mflix.comments from data/sample-mflix/comments.metadata.json.gz
2019-08-21T19:19:10.783+0900    restoring sample-mflix.movies from data/sample-mflix/movies.bson.gz
2019-08-21T19:19:10.784+0900    reading metadata for sample-mflix.theaters from data/sample-mflix/theaters.metadata.json.gz
2019-08-21T19:19:10.784+0900    reading metadata for sample-mflix.users from data/sample-mflix/users.metadata.json.gz
2019-08-21T19:19:10.808+0900    restoring sample-mflix.comments from data/sample-mflix/comments.bson.gz
2019-08-21T19:19:10.831+0900    restoring sample-mflix.theaters from data/sample-mflix/theaters.bson.gz
2019-08-21T19:19:10.864+0900    restoring sample-mflix.users from data/sample-mflix/users.bson.gz
2019-08-21T19:19:10.905+0900    restoring indexes for collection sample-mflix.theaters from metadata
2019-08-21T19:19:10.914+0900    restoring indexes for collection sample-mflix.users from metadata
2019-08-21T19:19:10.971+0900    finished restoring sample-mflix.theaters (1564 documents)
2019-08-21T19:19:10.971+0900    reading metadata for sample-mflix.sessions from data/sample-mflix/sessions.metadata.json.gz
2019-08-21T19:19:10.990+0900    finished restoring sample-mflix.users (183 documents)
2019-08-21T19:19:11.024+0900    restoring sample-mflix.sessions from data/sample-mflix/sessions.bson.gz
2019-08-21T19:19:11.069+0900    restoring indexes for collection sample-mflix.sessions from metadata
2019-08-21T19:19:11.125+0900    finished restoring sample-mflix.sessions (1 document)
2019-08-21T19:19:12.078+0900    no indexes to restore
2019-08-21T19:19:12.078+0900    finished restoring sample-mflix.comments (50304 documents)
2019-08-21T19:19:12.951+0900    restoring indexes for collection sample-mflix.movies from metadata
2019-08-21T19:19:18.773+0900    finished restoring sample-mflix.movies (23539 documents)
2019-08-21T19:19:18.773+0900    done

Your attached file size is 19.4MB.
Is file size right?

It is correct. The documents should be 23539 only. The test files were outdated which I believe after you have download new file, will be updated.

Did you try running the test case again? Let me know.


Thanks @Kanika

Is it solved!
My test code is old…

1 Like