Mongoose array can set of objects basically a reference to other mongoose document placed in other document. Our task is to place a new element to MongoDB array of objects.
To add a new element we can use the $push command. In our Post example we had tags which need to added while updating the post.
Post.updateOne({_id:pst}, { $push:{'tags':ctag._id} }, { safe: true, upsert: true} )
$push will add the tag id to the tags object array
Alternatively we can afford the following method too. The difference is that the first one used inside a update command.
post.tags.push(stag)