In the following post I will show how to append documents to an existing array of sub documents using Mongoose and MongoDB.
Mongoose lets you define mongo documents with sub documents, but it also offers a great shortcut to appending to the child collection.
Assume the following schema consisting of a language schema with belonging translations in a child collection.
It turns out that Mongoose provides a handy short cut for appending to the translations in a single update statement. The statement below will append the same set of translations to the translations collection of all language documents. However, you can also add a filter if you want to limit the set of language documents to update.
The key to this are the $push and $each operators.