My collection has this structure:
{
"_id" : "7ZEc8dkbs4tLwhW24",
"title" : "title",
"json" :
{
\"cells\":[
{
\"type\":\"model\",
\"size\":{\"width\":100,\"height\":40},
\"id\":\"11dc3b6f-2f61-473c-90d7-08f16e7d277a\",
\"attrs\":{
\"text\":{\"text\":\"content\"},
\"a\":{\"xlink:href\":\"http://website.com\",\"xlink:show\":\"replace\",\"cursor\":\"pointer\"}
}
}
]
}
}
Now I need to insert/update the field json.cells.attrs.a in my meteor app. All informations I got are _id (document ID) and id (id of element in cells). If a doesn't exist, the element should be created.
My attempt is not correct, as the query isn't looking for the elemID to get the correct element in the cells-array:
var linkObject = {"xlink:href":"http://newURL.com","xlink:show":"replace","cursor":"pointer"};
var docID = '7ZEc8dkbs4tLwhW24';
var elemID = '11dc3b6f-2f61-473c-90d7-08f16e7d277a'; // How to search for this 'id'?
var result = Collection.findOne({ _id: docID });
var json = JSON.parse(result.json);
// find id = elemID in 'json'
// add/update 'a'
// update json in mongoDB document