user: {
_id: objectId("5f5fd12521a9b27e849d9b7b")
profile:{
_id: objectId("5f5fd12521a9b27e849d9b7b")
firstName: "Vincent"
photo:{
_id: objectId("5f5fd12521a9b27e849d9b7b")
thumbnail: "/pictures/image.png"
original: "/pictures/original/image.png"
}
}
}
I want to update the photo field as an embedded schema under profile which is an embedded schema to user.
With Mongoose driver we can easily update nested documents.
Lets say you have fectched the document with mongoose, like below.
let document = await model.find ({ _id : '5f5fd12521a9b27e849d9b7b'});
Now you can simply assign the new data just like an object.
document.profile.photo= {...somestate}; await document.save();
That's it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.