1

我有三个表保存这些文档:

//user----tables:users        
{
    Id:"user/001"   
    Name:"Jack Losen"    
    ....
}


//schooling---table:schoolings
{
     Id:"schooling/001"
     Name:""       
     Major:"",
     EnrollYear:1983
}

 //user_schooling-----join table:user_schooling
{     
     user_id:"user/001"
     schooling_id:"schooling/001"
}

如何以一组学校教育为条件通过连接表查询用户ID:user_schooling?

例如:如果我想获取B年在A学校,或者(不是并且)在D年在C学校......(或更多)的用户的所有ID,那么我的查询条件可能是这样的:

condition: [
          {
              Name:"A"       
              ....
              EnrollYear:B
           },
           {
              Name:"C"       
             ...
              EnrollYear:D
           }
       ]
4

1 回答 1

1

rethinkdb 邮件列表中的人给出了正确答案:

r.table('user_schooling').filter(function(row) { 
  return r.table('schooling').get(row('SchoolingId')).do(function(school) {
     return r.expr([{Name:"MASTER", EnrollTime:2003}]).pluck('Name', '
   EnrollTime').contains(school.pluck('Name', 'EnrollTime')); 
  });
}).pluck("UserId")
于 2014-05-02T15:23:02.807 回答