python - RethinkDB - how to filter arrays in nested objects when updating? -


with rethinkdb, how update arrays in nested objects values filtered out?

consider following program, know how write update query filters out value 2 arrays contained in votes sub objects in documents 'dinners' table:

import rethinkdb r pprint import pprint   r.connect(db='mydb') conn:     pprint(r.table('dinners').get('xxx').run(conn))     r.table('dinners').insert({         'id': 'xxx',         'votes': {             '1': [1, 2, ],         },     }, conflict='replace').run(conn)  # how can update 'xxx' document value 2 # filtered out arrays contained in 'votes' sub object? 

you can use usual filter method object coersion:

def update_dinner(dinner):     return {         'votes': dinner['votes']         .keys()         .map(lambda key: [             key,             dinner['votes'][key].filter(lambda vote_val: vote_val.ne(2)),        ])         .coerce_to('object')     }  r.table('dinners').update(update_dinner).run(conn) 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -