RethinkDB, add elements to an array that's nested

100 Views Asked by At

Using the example here, I've only added one more level to notes, it's mapped to an object whose elements themselves hold arrays

{
    id: 10001,
    name: "Bob Smith",
    notes: {
        alpha:['note1','note2','note3'],
        beta:['note1','note2','note3']
    }
}

Cannot for the life of me figure out how to append elements to alpha and beta however. I've tried variations of this:

update({ 
    notes:{  
        alpha: r.row("alpha").append('note4')  
    } 
})

but am not really getting anywhere.
Any help would be much appreciated~

Oh and the error message was No attribute 'alpha' in object:

1

There are 1 best solutions below

1
On BEST ANSWER

You could do something like the following:

r.db('test')
 .table('user')
 .get('10001')
 .update({
   notes: {
     alpha: r.row('notes')('alpha').append('note4'),
     beta: r.row('notes')('beta').append('note4')
   }
 }).run();