19

I have this object:

{
    "id": "eb533cd0-fef1-48bf-9fb8-b66261c9171b" ,
    "errors": [
        "error1" ,
        "error2"
    ]
}

I simply want to append a new error to errors array. I tried:

r.db('test').table('taskQueue').get("eb533cd0-fef1-48bf-9fb8-b66261c9171b").update({'errors': r.row['errors'].append('appended error')})

but this did not work. It gives this error: "TypeError: r.row.errors is undefined"

My question is how to append an array?

Ayhan
  • 183
  • 1
  • 3
  • 15
Sincere
  • 477
  • 5
  • 18

1 Answers1

31
r.db('test').table('taskQueue').get("eb533cd0-fef1-48bf-9fb8-b66261c9171b").update({
    errors: r.row('errors').append('appended error')
})

So not r.row['errors'], but r.row('errors').

user3778037
  • 326
  • 4
  • 3
  • 1
    Thanks for this answer. Noob question about it, if `eb533cd0-fef1-48bf-9fb8-b66261c9171b` is a huge document, will going `.get` first not be expensive? e.g. would there be a way to just append an element directly into the datatype, instead of fetching the full document and then replacing the entire array in it? – kvz Sep 26 '16 at 17:30