如何通过 id 数组从 RethinkDB 获取许多文档?

How to get many documents from RethinkDB by array of ids?

我有一组 ID

ids = [1, 2, 3, 4, ...] #1000 ids

如何使用此功能:

r.table("users").get_all(1, 2, 3, 4, ..1000 ids.., index: "id")

我可以用

r.table("users").filter{ |doc| r.expr(ids).contains(doc["id"])}

但是在有 600 万文档的数据库上它太慢了

这里采用的方法SQL to ReQL cheat sheet

要将 ids 数组扩展为参数列表(get_all 方法所期望的),请使用 splat 运算符 (*array),如下所示:

ids = [1, 2, 3, 4]
r.table('users').get_all(*ids, index: 'id') # note the `*`