Search code examples
python-2.7rethinkdbrethinkdb-python

How to match nested values in RethinkDB?


I use Python client driver and the structure of my documents is :

{"key1": ["value1"], "key2": ["value2"], ..., "key7": ["value7"]}

let say "value7" is "In every time in every place, deeds of men remain the same"

I'd like to retrieve all documents that contain "deed" for key7.

I tried

r.db('db')
 .table('table')
 .filter(lambda row: row['key7'].match('^deed'))
 .run(conn)

but it doesn't work... I have the follwing message :

rethinkdb.errors.ReqlQueryLogicError: Expected type STRING but found ARRAY


Solution

  • Here is the solution :

    r.db('db')
     .table('table')
     .filter(lambda row: row['key7'].nth(0).match('^deed'))
     .run(conn)