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 回答