House3272
House3272

Reputation: 1037

RethinkDB, add elements to an array that's nested

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:

Upvotes: 1

Views: 94

Answers (1)

Tholle
Tholle

Reputation: 112787

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();

Upvotes: 1

Related Questions