我正在使用 ruby 驱动程序来重新思考 db,但我遇到了一些包含数组的嵌套元素的问题。
我的数据结构是这样的
[{"family_name"=>"Adam"},
{"family_name"=>"Bobby"},
{"family_name"=>"Crissy",
"groups"=>
[{"logo_url"=>"https://www.logourl.com/1111.png",
"name"=>"Sample Name 1",
"profile_url"=>"https://www.profileurl.com/groups?gid=1111"},
{"logo_url"=>"https://www.logourl.com/2222.png",
"name"=>"Sample Name 2",
"profile_url"=>"https://www.profileurl.com/groups?gid=2222"},
{"logo_url"=>"https://www.logourl.com/3333.png",
"name"=>"Sample Name 3",
"profile_url"=>"https://www.profileurl.com/groups?gid=3333"},
]},
{"family_name"=>"Bobby"},
{"family_name"=>"Hillton",
"groups"=>
[{"logo_url"=>"https://www.logourl.com/4444.png",
"name"=>"Sample Name 1",
"profile_url"=>"https://www.profileurl.com/groups?gid=4444"},
{"logo_url"=>"https://www.logourl.com/5555.png",
"name"=>"Sample Name 2",
"profile_url"=>"https://www.profileurl.com/groups?gid=55555"},
{"logo_url"=>"https://www.logourl.com/6666.png",
"name"=>"Sample Name 3",
"profile_url"=>"https://www.profileurl.com/groups?gid=12345"},
]}]
期望的结果是返回具有以“12345”结尾的“profile_url”链接的行。使用 Ruby 和 Javascript 的混合,我尝试了这个:
'r.table("profiles").filter{ |row| row['groups'].contains(r.js('function(group) { return group('profile_url').match("12345$") }'))}.run(conn)'
但是,它仍然没有返回结果,有没有明确的方法可以将它与 ruby 驱动程序一起使用?
期望的结果是
[{"family_name"=>"Hillton",
"groups"=>
[{"logo_url"=>"https://www.logourl.com/4444.png",
"name"=>"Sample Name 1",
"profile_url"=>"https://www.profileurl.com/groups?gid=4444"},
{"logo_url"=>"https://www.logourl.com/5555.png",
"name"=>"Sample Name 2",
"profile_url"=>"https://www.profileurl.com/groups?gid=55555"},
{"logo_url"=>"https://www.logourl.com/6666.png",
"name"=>"Sample Name 3",
"profile_url"=>"https://www.profileurl.com/groups?gid=12345"},
]}]
请帮助并提前感谢!:D