Reputation: 731
I have the following structure of json in db:
{
id: "dlsadas",
code : {
"312-43-1-3-v-d" : {
contents : [
{
"id" : 1
},
{
"id" : 2
}
]
},
"dbhwu-0dw-dw-dn" : {
contents : [
{
"id" : 5
},
{
"id" : 6
}
]
}
}
}
My question is :
How can i write an update statement so the contents array of key 312-43-1-3-v-d gets the object {id:8} appended.
From what i have read i would have to do:
r.table('table').filter(...).update({code : {key: r.row(contents).append({id:8}) }})
But i cant. Can this be achieved ?
Upvotes: 0
Views: 52
Reputation: 802
Try
r.table('table')
.get('dlsadas')
.update(function(doc) {
return {code: {
'dbhwu-0dw-dw-dn': {
contents: doc('code')('dbhwu-0dw-dw-dn')('contents').append({id:8})
}
}};
})
Or, perhaps consider changing your data format to something easier to work with - depending on your use cases.
Upvotes: 1