我有一个猫鼬模式,其中包含对象relatives
的数组。在relatives
数组中,我还有另一个对象history
数组。我想更新history
数组中的最后一个对象。我有ObjectId
和relatives
的{{1}},但没有history
数组的最后一个元素。我该怎么办?
模式
history
我正在尝试做类似的事情-
relatives:[
{
history: [
{
purposeOfVisit: {
type: String,
},
date:{
type:String
}
}]
}]
我知道我不能像const user_details = await user.findById(sub);
const relatives = await user_details.relatives.id(relativesId);
const lengthOfHistory = relatives.history.length;
await patient_details.update({
$set: {
history[lengthOfHistory-1]: {
purposeOfVisit:"xyz"
},
},
});
那样写作。因此,我该怎么做?