Meteor/MongoDB:按索引更新collection中的数组项
Meteor/MongoDB: Update an array item in a collection by index
这是我的 collection:
结构的概述
{
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
是动态的所以我不能hard-code任何东西。
上面的更新代码产生了这个错误:
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"}
这是我的 collection:
结构的概述{
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
是动态的所以我不能hard-code任何东西。
上面的更新代码产生了这个错误:
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"}