0

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);

});
4

1 に答える 1

1

I have gotten it resolved with help from the Slack Channel of RethinkDB.

Here is the code :

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);
  }).coerceTo('array').map(function(doc){
    return doc('userId');

  }).do(function(userIds){
    //return userIds;
    return r.db('locationtracker_development').table('user_rules').
      getAll(r.args(userIds),{index:'userId'});
  });
};
   r.do(get_distance(100)).do(function(dist){
      return run_rule('gXtzAawbc6',dist);
   });

Basically the objects returned needs to be coercedTo and Array and then using map and do functionality we can achieve querying multiple DBs.

于 2016-09-12T13:58:11.133 に答える