How to append an element to an array in rethinkdb
Asked Answered
I

1

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?

Incompressible answered 3/4, 2014 at 19:2 Comment(0)
M
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').

Malenamalet answered 26/6, 2014 at 6:37 Comment(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?Mayworm

© 2022 - 2024 — McMap. All rights reserved.