这是我的收藏结构的概述:
{
profile: {
first_name: 'Plop',
surname: 'Plopette',
...
},
medical_history: {
significant_illnesses: [
'Asthma',
'Diabetes'
],
...
}
}
如何访问和更新medical_history.significant_illnesses
数组中的某个项目?
我所拥有的是悲惨的失败:
Patients.update(Session.get("current_patient"), {
$push: {
"medical_history.significant_surgeries.surgeryIndex": $(event.target).val().trim()
}
});
注意,surgeryIndex
是动态的,所以我无法硬编码。
上面的更新代码会产生此错误:
Exception while simulating the effect of invoking '/patients/update'
errorClass {
error: 409,
reason: "MinimongoError: can't append to array using string field name [surgeryIndex]",
details: undefined, message: "MinimongoError: can't append to array using string field name [surgeryIndex] [409]",
errorType: "Meteor.Error"}