1

Any idea how can I select the Agent IDs inside the clients filter?

This is what I have now and it works, but I do not like that first we are waiting for the Agents to be selected and then we do another trip to the database to select the clients.

Is there a way that it can be all done in one trip with chaining, without the "then".

const clients = await r.table('agents').getAll(teamId, {index: 'teamId'})('id').then(agentIds =>
  r.table('clients').filter(client => r.or(
    r.expr(agentIds).contains(client('agentId')),
    r.table('tasks').filter(
      task => r.expr(agentIds).contains(task('agentId'))
    )('clientId').contains(client('id'))
  ))
);
4

1 回答 1

1

你可以写:

r.table('agents').getAll(teamId, {index: 'teamId'})('id').coerceTo('array').do(agentIds =>
  ...
)

构建一个获取 agentIds 的单个 RethinkDB 查询,将它们存储在一个变量中,然后执行其他操作。

于 2016-08-26T00:28:29.610 回答