docs icon indicating copy to clipboard operation
docs copied to clipboard

Missing example for updating a document inside an array

Open AtnNn opened this issue 8 years ago • 2 comments

As reported in https://github.com/rethinkdb/rethinkdb/issues/6182

The example might look like this.

.update(lambda row: {
  "array": row('array').map(lambda elem:
    r.branch(
      elem['name'] == 'Bob',
      elem.merge({ "age": 27 }),
      elem))})

Is there a better way to do this? Perhaps using change_at?

AtnNn avatar Nov 23 '16 20:11 AtnNn

Thank you!

tudorels avatar Nov 24 '16 06:11 tudorels

I have this problem:

after I run this:

r.db('chat').table('gruppi_chat').get(2).update(lambda row: {
  "passeggeri": row('passeggeri').map(lambda elem:
    r.branch(
      elem['nome'] == 'pigi',
      elem.merge({ "token": "none" }),
      elem))})

Recive this error: SyntaxError: missing ) after argument list

This is document test:

{
 "data_partenza": "2017-10-18" ,
"id": 2 ,
"nome": "Ciccio" ,
"passeggeri": [

    {
        "nome": "pigi" ,
        "token": "tokenProvaPigi"
    }

] 
}

p.s. update a nested array value it's really clunky

psummo avatar Aug 25 '17 14:08 psummo