Get comments ticket test fails - some data not there in collection?

The test:

npm test -t get-comments
server@1.0.0 test C:\Users\user1\Desktop\mongoDB\mflix-js
jest --passWithNoTests “get-comments”

Determining test suites to run...Setup Mongo Connection
 FAIL  test/get-comments.test.js (8.231s)
  Get Comments
    x Can fetch comments for a movie (131ms)
    √ comments should be sorted by date (1748ms)

  ? Get Comments > Can fetch comments for a movie
    expect(received).toBe(expected) // Object.is equality
    Expected: 2
    Received: 0
      10 |     const movie = await MoviesDAO.getMovieByID(id)
      11 |     expect(movie.title).toEqual("Once Upon a Time in Mexico")
    > 12 |     expect(movie.comments.length).toBe(2)
         |                                   ^
      13 |   })

The test from get-comments.test.js:
test("Can fetch comments for a movie", async () => {
const id = "573a13a6f29313caabd17bd5"
const movie = await MoviesDAO.getMovieByID(id)
expect(movie.title).toEqual("Once Upon a Time in Mexico")
expect(movie.comments.length).toBe(2)
})`

From mongo shell:
% db.movies.find( { '_id' : ObjectId('573a13a6f29313caabd17bd5') } ).pretty();
{ "_id" : ObjectId("573a13a6f29313caabd17bd5"), "title" : "Once Upon a Time in Mexico", "year" : 2003, "runtime" : 102, ...

% db.comments.find( { 'movie_id' : ObjectId('573a13a6f29313caabd17bd5') } );
No output.

I also tried the same queries from the Compass. The results are the same.

The code I wrote works fine with other movies _id, for example, _id: ObjectId('573a1399f29313caabced131'):
The movie is 1992 Gladiator and returns 3 comments. Verifies fine from shell or Compass or the aggregate pipeline I had written.

Is it possible the comments collection I have imported doesn’t have that data (the movie with title “Once Upon a Time in Mexico”)?

  • There are 45993 in movies collection.
  • There are 45000 in comments collection.

Please suggest.

Thanks,
Prasad.

Hi @Prasad_45636,

The movies collection seems fine, but comments collections seems incomplete. I have 150,094 documents in comments collection.

Please re-import data. I will recommend download handouts again and use mongorestore command with --drop option.

Kanika

I tried the restore just now, again. This time I got 5700 comments documents.

The restore is failing with some errors towards the end, while restoring the comments data:

mongorestore --drop --gzip --uri mongodb+srv://m220student:m220password@mflix-uck___.mongodb.net/test data

Output from the restrore:

2019-05-17T16:19:03.669+0530 finished restoring mflix.movies (45993 documents)
2019-05-17T16:19:06.237+0530 [######…] mflix.comments 2.84MB/10.3MB (27.6%)
2019-05-17T16:19:09.237+0530 [######…] mflix.comments 2.84MB/10.3MB (27.6%)
2019-05-17T16:19:12.237+0530 [######…] mflix.comments 2.84MB/10.3MB (27.6%)
2019-05-17T16:19:15.237+0530 [######…] mflix.comments 2.84MB/10.3MB (27.6%)
2019-05-17T16:19:18.237+0530 [######…] mflix.comments 3.27MB/10.3MB (31.8%)
2019-05-17T16:19:30.237+0530 [########…] mflix.comments 3.58MB/10.3MB (34.8%)
2019-05-17T16:19:33.237+0530 [#########…] mflix.comments 3.92MB/10.3MB (38.1%)
2019-05-17T16:19:33.783+0530 error: SSL errors: b07c065:x509 certificate routines:X509_STORE_add_cert:cert already in hash table
2019-05-17T16:19:33.805+0530 error: SSL errors: b07c065:x509 certificate routines:X509_STORE_add_cert:cert already in hash table
2019-05-17T16:19:34.626+0530 error: SSL errors: b07c065:x509 certificate routines:X509_STORE_add_cert:cert already in hash table
2019-05-17T16:19:34.635+0530 error: SSL errors: b07c065:x509 certificate routines:X509_STORE_add_cert:cert already in hash table
2019-05-17T16:19:34.644+0530 error: SSL errors: b07c065:x509
2019-05-17T16:19:34.650+0530 [########################] mflix.comments 10.3MB/10.3MB (100.0%)
2019-05-17T16:19:34.652+0530 restoring indexes for collection mflix.comments from metadata
2019-05-17T16:19:35.179+0530 finished restoring mflix.comments (150094 documents)
2019-05-17T16:19:35.181+0530 done

Please try again after removing /test from uri. If you are still unable to do it, please share your connection string.

Kanika

This time the restore worked without errors, after removing the ‘/test’ from URI. The counts match with what you had posted earlier (except for users collection; I have 183 and yours is 184).

The tests passed :slightly_smiling_face:

Thanks again.

Prasad.

1 Like

Glad to hear! :slight_smile:

Kanika