gpt4 book ai didi

javascript - rethinkdb eqJoin 匹配

转载 作者:行者123 更新时间:2023-12-03 07:56:02 26 4
gpt4 key购买 nike

您好,我正在使用 javascript 和 rethinkdb,并且我正在尝试弄清楚当目标 id 不在主表上而是在第二个表上时如何使用 eqJoin。

网站上的示例说明了这一点。

first table /players
[{name: 'anna', gameID:1}]

second table /games
[{id: 1, gameName: 'supergame'}]

但是我想加入的是这个

first table / players
[{id 1, name: 'anna'}]

second table / games
[{playerID: 1, gameName:'supergame'},
{playerID: 1, gameName:'megagame'},
{playerID: 1, gameName:'lamegame'}]

我读了一些关于 concatMap 的内容并尝试了这个,但这显然给了我错误,还有其他方法吗?

如果有的话我可以加入更多的 table 吗?

r.table("players").concatMap(function(play) {
return r.table("games").getAll(
play("id"),
{ index:"playerID" }
).map(function(games) {
return { left: play, right: games }
})
}).run(conn, callback)

最佳答案

右侧的表必须在您要获取的字段上有一个索引。从您的第二个示例来看,您已经在 games 上有了一个索引 playerID ;如果是这种情况,那么您应该能够将 index: 'playerId' 指定为 eqJoin 的参数。类似于 r.table('players').eqJoin('id', r.table('games'), {index: 'playerId'})

如果该索引存在,您可以使用indexCreate来创建它。

关于javascript - rethinkdb eqJoin 匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34798040/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com