I want to add an element to the array and add new field to the database if result of the query is an insert. If it is not an insert(if it is a update) I don't want to update the array and add new field.
To add new field on insert; I use $setOnInsert.
To add element to the array I use, $addToSet: { "children": {"age": 12}},
I tried but it seems that it is not possible to use $addToSet inside $setOnInsert. So how can add an array element if it is an insert?