尝试使用此示例连接ID数组:https://github.com/rethinkdb/rethinkdb/issues/1533#issuecomment-26112118
存储表格片段
{
"storeID": "80362c86-94cc-4be3-b2b0-2607901804dd",
"locations": [
"5fa96762-f0a9-41f2-a6c1-1335185f193d",
"80362c86-94cc-4be3-b2b0-2607901804dd"
]
}
Run Code Online (Sandbox Code Playgroud)
位置表格代码段
{
"lat": 125.231345,
"lng": 44.23123,
"id": "80362c86-94cc-4be3-b2b0-2607901804dd"
}
Run Code Online (Sandbox Code Playgroud)
我想选择商店并加入他们的商店位置.
来自ReThinkDB贡献者的原始示例:
r.table("blog_posts")
.concat_map(lambda x: x["comment_ids"].map(lambda y: x.merge("comment_id" : y)))
.eq_join("comment_id", r.table("comments"))
Run Code Online (Sandbox Code Playgroud)
我试图转换为JS
r.table("stores")
.concatMap((function(x){
return x("locations").map((function(y){
return x("locations").add(y);
}))
}))
.eqJoin("locations", r.table("locations"))
Run Code Online (Sandbox Code Playgroud)
结果
RqlRuntimeError: Expected type ARRAY but found STRING
我正在使用一系列键选择多个文档(如本答案中所示):
r.expr([person-id1, person-id2, person-id3])
.eqJoin(function(doc) { return doc; }, r.table("person"))
.zip()
Run Code Online (Sandbox Code Playgroud)
然后通过加入第二个表
r.expr([person-id1, person-id2, person-id3])
.eqJoin(function(doc) { return doc; }, r.table("person"))
.zip()
.eqJoin("company_id", r.table("employers"))
.zip()
Run Code Online (Sandbox Code Playgroud)
哪一切都很棒.我想要优化查询的唯一变化是,我只需要employer_name来自雇主表,因为存在相当大的数据,否则与"雇主"文档相关联.因为这个查询只包含eqJoins(),而没有"基础"表,是否有办法实现它?