-1

I have two documents like this:

//school       
{
     Name:""       
     Major:"",
     EnrollYear:1983
}


//schools
{
  id: "user/0",
  ownerId:""
  //an array that contains schools
  schools: [ 
              {
                 Name:""       
                 Major:"",
                 EnrollYear:1983
               }
               .....
           ]
}

How to take an array of schools as condition to query ownerIds?

for example:if I want to get the ownerIds of students who have been in A school at B year,or been in C school at D year...(or more),then my query condition may like this:

condition: [
              {
                  Name:"A"       
                  ....
                  EnrollYear:B
               },
               {
                  Name:"C"       
                 ...
                  EnrollYear:D
               }
           ]
Alex Luya
  • 9,412
  • 15
  • 59
  • 91

2 Answers2

1

Guys in rethinkdb mail list gave right answer:

r.table('schools').filter(function(row){
  return row('schools').pluck('name', 'enrollyear').contains(function(school){
    return CONDITION.pluck('name', 'enrollyear').contains(school);
 })
})
Alex Luya
  • 9,412
  • 15
  • 59
  • 91
0

You can build a query like this

r.table("users").filter(function(user) {
    return user("schools").contains(function(school) { 
        return school("Name").eq(A).and("school("EnrollYear").eq(B)
    }).and(
        user("schools").contains(function(school) { 
            return school("Name").eq(C).and("school("EnrollYear").eq(D)
        })
    )
})

Also, in your case, you have a "many to many" relation between users and schools. It's way better in this case to create a third table "link" that save relation between user and school. It would make things way easier to query.

neumino
  • 4,342
  • 1
  • 18
  • 17