Lecture: Updating Documents: replaceOne() - Unable to execute the steps

Hello,
I don’t expected results as in the lecture video when I ask mongo shell to return the results for “doc”.

Here are the results steps I am following:

let filter = {title: “House, M.D., Season Four: New Beginnings”}
filter
{“title”: “House, M.D., Season Four: New Beginnings”}
let doc = db.movieDetails.findOne(filter);
doc
null
(it should return the results of the findOne() query, but it returns “null” instead.)

Please let me know where am I going wrong. Thanks!

3 Likes

I actually figured out a way around it. I made a guess that “doc” probably is a reserved variable in the newer version and substituted the variable name with “doc1” instead and it works just fine now.

2 Likes

Found out FINALLY!!!

  1. In my case my first mistake was about db I was in, so I just had to use video.
  2. And the second problem was that in lecture he uses ‘movies’ collection, while we don’t have that, but ‘movieDetails’ instead. So we just have to change this comand let doc = db.movies.findOne(filter); to this one let doc = db.movieDetails.findOne(filter);
2 Likes

Thank you - I totally missed that the handout was referring to db.movies rather than db.movieDetails and was wondering what I was doing wrong!

Thank you everyone for help! I was stuck with this null for doc

Thank you !
Also I had another problem.
I ran let filter = {title: “House, M.D., Season Four: New Beginnings”}, and after that ran it again after some changes of replaceOne.js file, what gave an error TypeError: redeclaration of let filter.
So I simply changed the name to another, for example to filter1.
Also I tried to run similar code from changed replaceOne.js file with name replaceOne2.js, using load(“replaceOne2.js”), like in video Loading Data into Your Sandbox Cluster. This also worked fine.

For my case, i got the same error due to i was used find() instead of findOne(). I remind you that i have mongod(Mongodb Entreprise Server ) version 4.0.7. Thanks to all for your explainations.