0

Hello i need somehow to pass the filter method 2 or more arguments. Something like r.table("N/A").filter(function(arg1,arg2){..code here})

I need it for the following:

I have a data structure like the following:

"client":{
"name":"andrew",
"coords":{"lat":200,"long":300} 
}

I want to get a list of all clients , and for each client in this list i want his properties merged with the other clients that respect a filter predicate.I need to pass multiple arguments to filter function.

clients{

client:{
"name":"andrew",
"coords":{"lat":200,"long":300}
"neighbours":{ 
  "name":"Dean","coords":{"lat":100,"long":200}
  "name":"Sean","coords":{"lat":55,"long":120}
}
client:{
 "name":"Dean",
 "coords":{"lat":100,"long":200}
 "neighbours":{
  "name":"Sean","coords":{"lat":55,"long":120}
}
client:{
 "name":"Sean",
 "coords":{"lat":100,"long":200}
 "neighbours":{}
}

}

My failed attempt:

r.db("cldb").table("clt").pluck(
  {"name","coord"}).merge(function(currentClient){
  return {
  r.db("cldb").table("clt").filter(
    function(currentClient,neighbourClient){
    currentClient("lat").gt(neighbourClient("lat"))
                        .and(currentClient("long").gt(neighbourClient("long")))}
    )}
  })
Bercovici Adrian
  • 8,794
  • 17
  • 73
  • 152

1 Answers1

0

Not quite sure if i understood your question correctly.

r.db("cldb")
.table("clt")
.pluck(["name", "coord"]) // <- [] instead of {}
.merge(function (currentClient) {
    return {
        // When using objects, you have to specify a property name.
        propertyNameThatYouWant: r.db("cldb")
        .table("clt")
        .filter(function (neighbourClient) {
            currentClient("lat")
            .gt(neighbourClient("lat"))
            .and(currentClient("long").gt(neighbourClient("long")))
        })
    }
})

So not tested, but i think that should work. When you nest two functions, the argument of the outer function is available in the inner function.

Moritz Mahringer
  • 1,240
  • 16
  • 28