Skip to content Skip to sidebar Skip to footer

Updating Subarray Object With Mongoose Not Working

My MongoDB database main document looks like this: { '_id': { '$oid': '568ad3db59b494d4284ac191' }, 'name': 'Myclass', 'items': [

Solution 1:

If you assign item to a new value you are not actually changing the content of the array. item is just a reference to the element in the array.

What you probably want is to edit the content of the array by merging the two objects item and req.body.

require('extend'); // npm install extendextend(item, req.body);

That will actually update the value in the array which will then be saved.

However, I recommend updating the subdocument using mongoose as explained here: Mongoose find/update subdocument

Post a Comment for "Updating Subarray Object With Mongoose Not Working"