5. Inserting, Updating, and Deleting Documents
Activity 5.01: Updating Comments for Movies
Solution:
Perform the following steps to complete the activity:
- First, update the
movie_id
field in all three comments. As we need to apply the same update to all three comments, we will use thefindOneAndUpdate()
function along with the$set
operator to change the value of the field:db.comments.updateMany( { "_id" : {$in : [ ObjectId("5a9427658b0beebeb6975eb3"), ObjectId("5a9427658b0beebeb6975eb4"), ObjectId("5a9427658b0beebeb6975eaa") ]} }, { $set : {"movie_id" : ObjectId("573a13abf29313caabd25582")} } )
Using the update command, we find three movies by their
_id
, providing their primary keys using...