Lecture: Upsets

let detail = {“title”:“The Rock”,“year”:2016,“rated”:“PG-13”,“runtime”:144,“countries”:[“USA”,“UK”],“genres”:[“Adventure”,“Drama”,“Sci-Fi”],“director”:“Ridley Scott”,“writers”:[“Drew Goddard”,“Andy Weir”],“actors”:[“Matt Damon”,“Jessica Chastain”,“Kristen Wiig”,“Jeff Daniels”],“plot”:“During a manned mission to Mars, Astronaut Mark Watney is presumed dead after a fierce storm and left behind by his crew. But Watney has survived and finds himself stranded and alone on the hostile planet. With only meager supplies, he must draw upon his ingenuity, wit and spirit to subsist and find a way to signal to Earth that he is alive.”,“imdb”:{“id”:“tt1111111”,“rating”:8.2,“votes”:187881},“tomato”:{“meter”:93,“image”:“certified”,“rating”:7.9,“reviews”:283,“fresh”:261,“consensus”:“Smart, thrilling, and surprisingly funny, The Martian offers a faithful adaptation of the bestselling book that brings out the best in leading man Matt Damon and director Ridley Scott.”,“userMeter”:92,“userRating”:4.3,“userReviews”:105024},“metacritic”:80,“type”:“movie”,“poster”:“http://ia.media-imdb.com/images/M/123456.jpeg",“awards”:{“wins”:8,“nominations”:14,“text”:"Nominated for 3 Golden Globes. Anoter 8 winds & 14 nominations”}}; db.movieDetails.updateOne({“imdb.id”:detail.imdb.id},{$set: detail},{upserts: true});

{ acknowledged: 1,
insertedId: null,
matchedCount: 0,
modifiedCount: 0,
upsertedCount: 0 }

I am trying to perform an upsert based on imdb.id value tt1111111 which doest exists as part of the movieDetails collection. My understanding is the data should get inserted. But if you look at the result the upsertCount is 0 and the document has not got inserted… Let me know if am missing something…

Hi @Rakesh_Ramasamy,

The option is upsert

I believe the goal with be better achieved including details variable in the <filter> slot, but you’ll find out.


Please surround the code blocks with triple backticks
like so
```
Code block here
```