Database
[{username:"bob",user_id:"12345",post:"Hey everyone, this is my post",photoID:"RANDOM_GENERATED_NUMBER",/** each user has their own photoID*/comments:[{username:"tom",user_id:"54321",post:"Hey everyone, this is comment 1",photoID:"RANDOM_GENERATED_NUMBER",/** each user has their own photoID*/responses:[{username:"bob",user_id:"12345",post:"Hey everyone, this is response 2",photoID:"RANDOM_GENERATED_NUMBER",/** each user has their own photoID*/},{username:"will",user_id:"35791",post:"Hey everyone, this is response 2",photoID:"RANDOM_GENERATED_NUMBER",/** each user has their own photoID*/},],},{username:"bob",user_id:"12345",post:"Hey everyone, this is comment 2",photoID:"RANDOM_GENERATED_NUMBER",/** each user has their own photoID*/responses:[],},],},{username:"bob",user_id:"12345",post:"Hey everyone, this is my post",photoID:"RANDOM_GENERATED_NUMBER",/** each user has their own photoID*/comments:[{username:"tom",user_id:"54321",post:"Hey everyone, this is comment 1",photoID:"RANDOM_GENERATED_NUMBER",/** each user has their own photoID*/responses:[{username:"bob",user_id:"12345",post:"Hey everyone, this is response 2",photoID:"RANDOM_GENERATED_NUMBER",/** each user has their own photoID*/},{username:"will",user_id:"35791",post:"Hey everyone, this is response 2",photoID:"RANDOM_GENERATED_NUMBER",/** each user has their own photoID*/},],},{username:"bob",user_id:"12345",post:"Hey everyone, this is comment 2",photoID:"RANDOM_GENERATED_NUMBER",/** each user has their own photoID*/responses:[],},],},]
Query
db.collection.update({},{$set:{"comments.$[c].photoID":"NEW_RANDOM_GENERATED_NUMBER","comments.$[].responses.$[r].photoID":"NEW_RANDOM_GENERATED_NUMBER",},},{multi:true,arrayFilters:[{"c.user_id":"12345",},{"r.user_id":"12345",},],})