RethinkDB:​​如果一个表不包含另一个表的键,则合并两个表

RethinkDB: merge two tables if one does not contains key of other

我正在合并两个 table Table 1 的主键存在于 table 2 中,但在某些情况下 table 2 中没有外键。这会引发错误,即不存在键。 我只想在键存在的情况下将 table 与条件合并;

    r.table('sport').filter({sport_id:sport_id}).merge(function(doc){
    return {
        terminology: r.table('sport_terminology').get(doc("terminology_id"))
    }
})
    .run(conn, sport);

现在,如果运动不包含术语作为键,则它会触发错误。如果密钥不存在,请给我合并绕过的解决方案

从你的问题中有点不清楚你遇到了什么问题,因为你没有post编辑你得到的异常。

我假设对于某些文档,您得到的是 "No attribute 'terminology_id' in object"。如果是这种情况,只需添加一个 default() 值,例如:

r.table('sport').filter({sport_id:sport_id}).merge(function(doc) {
  return {
    terminology: r.table('sport_terminology')
      .get(doc("terminology_id").default(null))
  }
})

如果不是这样,请post错误信息。