How to update the array objects if id exist otherwise insert in mongodb

Solution 1:

Alright do this to update or insert if it's not there

db.posts.update({book: [array you want to update]},
     {New Array},
         {upsert: true},
 )