If you have a list of objects you want to replace, something like this should work:
r.expr(myArrayOfDocuments)
.forEach(function(row) { return r.table('my_table').get(row('id'))
.replace(row); })
.run(conn, callback);
This assumes your primary key is id
, but if you want a more generic solution, you can replace id
with r.table('my_table').info()('primary_key')
.
The reason the query you posted doesn't work is that r.table('my_table').replace(...)
is trying to replace every row in your table with the argument you gave it - in this case, an array rather than the expected dict. Normally r.table('my_table').replace(...)
should be given a function to generate the new row based on the old row. See the documentation for replace
for more details or examples.