Update embedded mongoose document in array Update embedded mongoose document in array mongoose mongoose

Update embedded mongoose document in array


Sorry for late answer; I think this is what you want to do with mongoose.

Books.findOneAndUpdate({        _id: 1,        'ratings._id': id1    },    {        $set: {            'ratings.$.rating' : 3        }    }, function(err, book){        // Response    });


Positional operator may help you:

db.books.update(   // find book by `book_id` with `rating_id` specified   { "_id": book_id, "ratings._id": rating_id },   // set new `value` for that rating   { $set: { 'ratings.$.rating': value }} );

$ will save position of matched document.