Node.js bson module dependency issue? Create/Update Comments, Get Comments


I have taken this course before, and have answered the Get Comments and Create/Update Comments tickets successfully, but this time, I am having some trouble.

My code this time was substantively similar to last time around, but even if I use the exact same code as last time, an error relating to the “new” keyword is thrown.

So, within usersDAO and commentsDAO, I changed instances of ObjectId() to new ObjectId().

When I did this for the getMovieById() problem, both the unit tests and status page validated. However, when I did this for the addComment() and updateComment() problems, the unit tests validated, but the status page gives me a “Create/Update Comments: Unable to post a comment” error.

I noticed when installing mflix, there is a new bson dependency in the node.js packages file. I suspect this has something to do with the issue.

I also noticed by looking in Atlas, that the total documents in the comments collection increases by 1 each time I run the unit test, while when I run the status validation page, it does not increase. I am not sure whether the non-deletion of comments inserted by the unit test will affect things. Also, in the node.js log, I get a 500 error when reloading the status page.

I have tried dropping and restoring the database, looking in the forums (where I notice there are various problems relating to this ObjectId() problem, but no solution seemed to do the trick for me) and looking at the related test js files to try to figure it out, but to no avail.

I am sure there is an easy solution here, or that I am missing something trivial relating to the above. I’ll post code if necessary for diagnosis though.


1 Like

Hi @0per8,

I am sorry for your experience. I am trying to replicate the issue on my end.
Meanwhile, I assume that you have downloaded the handouts from the current offering and you have re-imported the data into your cluster.
If by any chance, you are using the old handout directory of mflix-js, I would highly recommend to download again and start from scratch.


Hi Kanika,

Yes, I did download the new handout; this is how I noticed the difference in mflix/packages.json dependencies between this and last month’s courses. This time bson 4.0.2 is listed explicitly as a dependency. For last month’s course, bson module seems to have been version 1.1.0. Maybe I should try installing this older version of bson module for this iteration of the M220, despite what is in the new packages.json file?

Before I started work on this month’s course, I moved my old work to a different directory and followed the instructions for the current course, downloading the new materials and putting them into a mflix-js directory as per the instructions for the current course. When I started the node.js server for the first time, it threw an error saying it cannot find module ‘bson’, so I explicitly installed it using “npm install bson”.

After I ran into this issue with Create/Update comments, it threw an error saying I needed to use the new keyword in front of ObjectId(). I did this and unit tests passed. When the status page did not, I uninstalled/reinstalled all node packages, and downloaded/reinstalled the entire DB. This is how I noticed that every time I ran the unit test for Create/Update Comment, it was leaving a document in my comments collection over on Atlas.

Along the bottom of the picture, you can see an example of the documents being left in the database.

If my code will help diagnosis, I will be happy to give it (post it or DM), but it is just previously-working (May 18 2019 class) code with the “new” keyword in front of ObjectId() for the get comments ticket and create/update comments ticket.

Thanks for your help-

(edited for clarity by H)

Thank you so much for the detailed diagnosis. :slight_smile:

I am just doing the same process and will ask for your code if needed. Really appreciate for all the hard-work.


Hi @0per8,

I am able to pass the test without any change in the number of documents in comments collection.

Please do the following to debug the issue:

  • Restore the data again from the handouts.
  • Check (Share) the diff between the code changes commentsDao.js from the handouts file.
  • Hard-refresh the browser to clear out the cache.


Hi Kanika,

I have followed the steps you recommended and I still have the problem “bson module not found” shown in the picture.

However, I believe I have found the solution. Instead of using “npm install bson”, I used the command “npm install bson@1.1.0”. I have made no other changes to my code (I even left the “new” keywords in place) and now everything works.

I guess something requires this specific version of the bson module, but it is not being automatically installed via the handout for me somehow. I am still not sure why.

Anyway, it is fixed for me. Thanks for your guidance and effort!


1 Like