Hey all,
So in the video, I noticed that the instructor wanted to assign a new property of box office to the “The Martian” document… He assigned the document to a variable, removed the id property, added the boxOffice property, and then inserted this second version into the collection.
So normally in JavaScript, assigning a variable to equal an object means the variable has a reference to that object - any changes made to that object via the variable will also affect the original object.
let a = {key: “value”};
let b = a;
b.id = 4; //a will also have id = 4;
So does MongoDB’s findOne return basically a deep copy of the object? And not a reference to it?
Looking up the findOne operation on the MongoDB docs, I noted this line: " Although similar to the find()
method, the findOne()
method returns a document rather than a cursor."
So the document returned is not a direct reference to the document? Am I understanding this correctly?
-Carlos