首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何通过一个表的pid将两个表与另一个表的嵌入数组字段值连接起来?

如何通过一个表的pid将两个表与另一个表的嵌入数组字段值连接起来?
EN

Stack Overflow用户
提问于 2015-08-06 08:06:27
回答 1查看 250关注 0票数 0

(对不起,问题标题很尴尬)你好,我有两个表,上面有这样的数据:

代码语言:javascript
复制
//friend_group table
{
    .....
    {
       "id":"user-me"//owner id 
       "FriendGroups":[
             {"id":"friendGroup_1","Members":["friend_1","friend_2"]},
             {"id":"friendGroup_2","Members":["friend_1","friend_3","friend_4"]},
        ]
    }
    .....
}

//friend table
{
    .....
    {"id":"friend_1","Skills":["java","c++"]}
    {"id":"friend_2","Skills":["python","ruby"]}
    {"id":"friend_3","Skills":["golang","c++"]}
    {"id":"friend_4","Skills":["javascript","ruby"]}
    ....
}

我想查询一下“用户-我”的朋友,他们被分配到"friendGroup-2“组,并具有"c++”技能,因为给定的数据结果应该是:

代码语言:javascript
复制
["friend_1","friend_3"]

我试过这样做:

代码语言:javascript
复制
r.db("test").table("friend").filter(function(u){
    return r.table("friendGroup").get("user-me")("FriendGroups").filter(function(fg){
      return fg("id").eq("friendGroup_2").and(fg("Members").contains(u("id")))
})}).pluck("id")

我的剧本有什么问题?

更新我的脚本是:

代码语言:javascript
复制
r.db("test").table("friend").filter(function(u){
    return r.table("friendGroup").get("user-me")("FriendGroups").filter(function(fg){
      return fg("id").eq("friendGroup_2").and(fg("Members").contains(u("id")))
})}).filter(function(u){return u("Skills").contains("skill-2")}).pluck("id").pluck("id")
EN

回答 1

Stack Overflow用户

发布于 2015-08-06 09:21:22

原来将返回的“过滤器”改为“包含”将解决这个问题,正确的脚本应该是:

代码语言:javascript
复制
r.db("test").table("friend").filter(function(u){
return r.table("friendGroup").get("user-me")("FriendGroups").**contains**(function(fg){
  return fg("id").eq("friendGroup_2").and(fg("Members").contains(u("id")))
})}).filter(function(u){return u("Skills").contains("skill-2")}).pluck("id").pluck("id")
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31850165

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档