Lecture : upsert

In this lecture the final code showed was :

db.movieDetails.updateOne ({
“imdb.id” : detail.imdb.id
}, {
$set :detail
upsert: true

My doubt about this code is, in the filter section (“imdb.id” : detail.imdb.id) the detail.imdb.id is another collections in the sandbox, over the same db ?

Thanks in advance

Hi @pibardup70,

In this lecture, the detail object is an example to show the structure of the document.

Here we are comparing the imdb.id field of movieDetails collection with imdb.id field of the detail object. If the filter condition matches, the document will be replaced, else the detail object will be saved as a new document in the movieDetails collection.

I hope it helps. If you still have any doubt, please let me know.


Hi Sonali…
Thanks for your response…
I looking for a detail object and I can’t find at movieDetails collections.
And If detail is an object then I must expect to find it like a component of a field ?

Thanks in advance

I also do have a doubt here.

How the mongo translated the file ‘theMartian.js’ as detail collection?

Hi @Atila_66821,

The detail variable stores a document. The instructor placed it in a file called theMartian.js.

If you run this command from the mongo shell, it will load the object in your environment and then you can use it.


Hope it helps!

~ Shubham

1 Like

Now it is clear enough! :slight_smile: