2016-09-12 19 views
0

RethinkDBでは、複数のクエリを複数のデータベーステーブルにチェーンしようとしています。このアイデアは、従来のdBのストアドプロシージャと同じです。基本的には、デバイスに接続されているすべてのユーザーにクエリを実行し、各ユーザーはルールテーブルからルールを取得しようとします。 ここに私が書いているReQLの要点があります。しかし、forEachは書き込みクエリーを必要とし、読み込みを行わず、do()も失敗しているので動作しません。助言がありますか?ReathinkDB:​​チェーンで複数のテーブルを照会

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

}); 

答えて

1

私はRethinkDBのSlack Channelの助けを借りて解決しました。ここで

はコードです:

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

は基本的にオブジェクトがcoercedToと配列するニーズを返され、その後、マップを使用して、我々は、複数のDBを照会達成することができた機能を実行します。

関連する問題