RethinkDB では、複数のクエリを複数のデータベース テーブルにチェーンしようとしています。考え方は、従来の dB のストアド プロシージャと同じです。基本的に、デバイスに接続されているすべてのユーザーにクエリを実行し、ユーザーごとにルール テーブルからルールを取得しようとします。これが私が書いているReQLクエリの要点です。しかし、 forEach は、読み取りではなく書き込みクエリが必要であり、 do() が失敗しているため、機能しません。助言がありますか?
const get_distance = function(location){
const final_location = 500;
return r.expr(500).sub(location);
};
const run_rule = function(device,distance){
return r.db('locationtracker_development').table('customer_details').filter(function(cust){
return cust("deviceId").contains(device);
}).pluck("userId").forEach(function(userName){
//TODO Work on each user
return r.db('locationtracker_development').table('user_rules').filter({'userId':userName('userId')});
});
};
r.do(get_distance(100)).do(function(dist){
return run_rule('gXtzAawbc6',dist);
});