如何对 rethinkdb 中数组中的每个值执行连接

How to perform join for each of the value in array in rethinkdb

我在一个提供媒体内容的网络平台上工作。我在平台中添加了类似于 twitter 的 'follow' 功能。每个用户都必须从他们在我的平台上关注的人那里获得更新。

我对如何为 'follow' 功能设计数据库感到困惑。这是我试过的。

包含用户信息的用户 table 也有一个关注数组。

{ 
  id: 'f344cf91-c14f-4772-b481-a5fea8f3107a',
  name: 'something',
  email:'abc@gmail.com",
  username:'adadas',
  password:'234231wwe1'
  follow :  []
}

follow 数组用于跟踪当前用户关注的其他 user-ID。 我想通过以下数组中的用户获取 posts。

帖子存储在另一个 post table.

我想加入跟随数组中的用户 ID 和 post table 以从每个用户检索 posts。 我认为 for_each 命令用于遍历数组元素。但我不确定如何将数组的每个元素与 table post 连接起来 有人可以帮我解决这个问题吗?我也不确定这是在 rethinkdb 中实现这种功能的有效方法,因为它需要很多连接。

您可能想要这样的东西:

r.table('user').get(USER_ID)('follow').eqJoin(function(row) { return row; }, r.table('post'), {index: 'user_id'})