使用 forEach and/or toArray 跨不同表的迭代命令

Iterative commands to across different tables with forEach and/or toArray

我需要遍历主 table 并将新文档添加到不同的 table,每个 id:name: 条目与主 table.

我已经阅读了 relevant documentation, which is shamefully sparse, and I found this SO post 关于迭代同一 table 内的对象属性的内容,但这并不适用,因为我想迭代 table 上的对象,而不是属性在一个对象中,并将结果应用于新的 table(而不是相同的 table)。

我可以遍历 table 的长度并创建与新 table 中的某些字段匹配的文档吗?

更具体地说:我的数据库 primary_table 中的文档有字段 id:name. 如何将这些 ID 和相应的名称迁移到详细信息 payment_history 使用 forEachtoArraynext?

中的一个或组合

我的尝试:

r.db('client').table('basic_info').forEach(
  function(id){
    return r.db('client')table('payment_history').insert(
      {
       id: r.db('client').table('basic_info').get(id).getField('id'),  
       name: r.db('client').table('basic_info').get(id).getField('name')
       }  
      );
  }
);

提前致谢

你可以这样写forEach

r.db('client').table('basic_info').forEach(function(row) {
  return r.db('client').table('payment_history').insert(
    {id: row('id'), name: row('name')});})

但这样写可能会更好:

r.db('client').table('payment_history').insert(
  r.db('client').table('basic_info').pluck('id', 'name'))