My JSON currently looks like this:
{
\"_id\" : 393,
\"item\" : 34,
\"comments\" : [
{
\"name\" : \"kevin\",
\"message
Using $elemMatch and $
operator you can update your documents check below query :
db.collectionName.update({"_id":393,"comments":{"$elemMatch":{"name":"kevin"}}},
{"$push":{"comments.$.messages":39}})
Something like this will work:
var newMessage = '39';
comments.forEach(function(item) {
if (item.name === 'kevin') {
item.comments.push(newMessage);
}
});