Here is an example.
db.docs.insert({_id: 1, A1: [{A2: [1, 2, 3]}, {A2: [4, 5, 6]}]})
If you know the index of the subdocument that you want to insert, you can use dot notation with the index (starting at 0) in the middle:
db.docs.update({_id: 1}, {$addToSet: {'A1.0.A2': 9}})
This leads to:
{ "A1" : [ { "A2" : [ 1, 2, 3, 9 ] }, { "A2" : [ 4, 5, 6 ] } ], "_id" : 1 }
source share