mongoose update push to nested array code example
Example 1: mongodb mongoose push into nested array
db.collection.updateOne(
{ "_id": ID, "playlists._id": "58"},
{ "$push":
{"playlists.$.musics":
{
"name": "test name",
"duration": "4.00"
}
}
}
)
Example 2: mongoose update array push multiple
Kitten.update(
{ name: 'fluffy'},
{
$push: {
values: {
$each: [2, 3]
}
}
}
)
.then(result => {
console.log(result)
})
.catch(err => {
console.error(err)
})