Search code examples
rethinkdbrethinkdb-python

Insert data from nested list into separate table in rethinkdb


I have a table with about 2m records with following structure:

{
    "fields": "values",
    "transactions": [
         {
              'from': '...',
              'value': '...'
         }
    ]
}

Now I want to separate the data in transaction field to be separate records in another table. Is there some native way to do it in rethinkdb?


Solution

  • I was able to do it using concatMap:

    r.table('transactions').insert(
       r.table('records').concatMap(function (doc){return doc('transactions')})
    )