Using Ruby Driver to create a complicated query in Rethinkdb's Reql -
i using ruby driver rethink db , running problem nested elements has arrays.
i have data structured this
[{"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"}, ]}]
the desired result return row has 'profile_url' link ends "12345". using mix of ruby , javascript, have attempted :
'r.table("profiles").filter{ |row| row['groups'].contains(r.js('function(group) { return group('profile_url').match("12345$") }'))}.run(conn)'
however, still not returning result, there clear way use ruby driver???
the desired result be
[{"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"}, ]}]
please , in advance!!! :d
i think want:
r.table('profiles').filter {|row| row['groups'].contains {|group| group['profile_url'].match('12345$') } }
Comments
Post a Comment