I have a nested array of documents in meteor mongo like so:
{
"_id" : "XBsaRPrangiS7xmAc",
"chartData" : [
{
"sectionID" : ObjectId("74d5541d775e4836478edff7"),
"sectionName" : "abc",
"sectionData" : [more nested documents...]
},
{
"sectionID" : ObjectId("c17841e1b2e46a5f4f43c41d"),
"sectionName" : "def",
"sectionData" : [more nested documents...]
}
...more sections...
]
}
Based on several stackoverflow answers, I have tried to update fields (eg. chartData.sectionName) like so on the server:
ChartData.update({
'_id':'XBsaRPrangiS7xmAc',
'chartData.sectionID': new Mongo.ObjectID("74d5541d775e4836478edff7")
},{
'$set': { 'chartData.sectionName': 'hello'}
});
Now I'm getting an error message which says: "Exception while invoking method 'updateSectionName' MongoError: cannot use the part (chartData of chartData.sectionName) to traverse the element".
What's wrong with my code and what is the proper way to update nested documents in meteor?