How to add a field in the subdocument MongoDB not deleting the already existing field?

Help, I do not understand the logic!
I have a collection of galleries, and each of them can have an array of albums.
And gallery and albums can have their picture thumbnail to display in the list.
I add the field image to the gallery without any problems, and everything is fine Merida:

db.photos.update({_id:"1587050015794"},{$set:{image:"image.link"}})

But the album fails to add a field, zeroing is not already available. The old object is replaced with the new, so I have to send all the fields to avoid losing them....
Send this request.

db.photos.update({"_id" : "1587050015794","albums._id": "1587050121637"},{$set: {'albums.$':{image:"image.link"}}})


{
 "_id" : "1587050015794",
 "slug" : "1",
 "description" : {
 "fr" : "1",
 "EN" : "1"
},
 "albums" : [
...,
{
 "_id" : "1587050121637",
 "slug" : "11",
 "description" : {
 "fr" : "11",
 "EN" : "11"
},
 "gallery" : [ ]
},
...
}

Thank you!
April 19th 20 at 12:23
2 answers
April 19th 20 at 12:25
to add to the array $push
https://docs.mongodb.com/manual/reference/operator...

db.photos.update(
 {_id:"1587050015794"}, 
 { $push: { 
 albums: { slug: 6666666 } 
 } 
)
April 19th 20 at 12:27
But I don't need to add a new album, and you need to change one property, or add it.

Find more questions by tags MongoDB