0

I have below json data.

{
    "_id" : ObjectId("57d66e95e5a5532a6ac91df6"),
    "array1" : [ 
        {

            "_id" : ObjectId("57d6857005bf3530bd25e26d"),
            "array2" : [ 
                {
                    "_id" : ObjectId("57d6857005bf3530bd25e26e"),
                    "data1" : "VoiceCall",
                    "data2" : 12345
                }, 
                {
                    "data1" : 12848,
                    "data2" : "VideoCall",
                    "_id" : ObjectId("57d6858205bf3530bd25e26f")
                }
            ]
        }
    ]
}

now I want to update like this:

db.getCollection('test').update({
   _id: ObjectId('57d66e95e5a5532a6ac91df6'),
    "array1.array2._id":ObjectId('57d6858205bf3530bd25e26f')
    },{$set:{"array1.array2.$.data1":121212}})

but this is not allowed in mongodb.

Please help to update it.

4J41
  • 5,005
  • 1
  • 29
  • 41
Sachin
  • 2,912
  • 16
  • 25
  • You might want to read this, as it seems to be a mongodb limitiation http://stackoverflow.com/questions/18573117/updating-nested-arrays-in-mongodb-via-mongo-shell – Fowotade Babajide Sep 28 '16 at 13:04
  • @FowotadeBabajide I have checked this issue but still trying to find if someone have done this. – Sachin Sep 28 '16 at 13:07

0 Answers0