rethinkdb 获取不在其他文档中的所有记录

rethinkdb get all record not in other document

我们正在将 rethinkdb 与 nodejs 一起使用。我有一个用户 table,我想获取所有不在 userdetail table

中的 isActive 用户

用户Table

{
"id":  "1" ,
"fName":  "A" ,
"lName":  "B" ,
"isActive": true
}
{
 "id":  "2" ,
"fName":  "C" ,
"lName":  "D" ,
"isActive": true
}
{
"id":  "3" ,
"fName":  "E" ,
"lName":  "F" ,
"isActive": true
}
{
"id":  "4" ,
"fName":  "G" ,
"lName":  "H" ,
"isActive": false
 }
 {
 "id":  "5" ,
 "fName":  "I" ,
 "lName":  "J" ,
 "isActive": true
  }

用户详细信息

{
"id":  "12" ,
"users":  [{"userId":"1"},{"userId":"2"}]
}

现在我想要所有 isActive 用户,除了 id 1 和 2

所以我尝试了以下查询,但它不起作用

r.db("mydb").table("users").filter( function(u) 
{ return r.db("mydb").
 table("userdetails")("userId").contains( u("id")         
 ).not(); })

看来这就是你想要的

r.table('userdetails')('users').concatMap(r.row('userId')).coerceTo('ARRAY').do(
   function(userdetails) {
    return r.table('user').filter(function(user) {
      return user('isActive').and(userdetails.contains(user('id')).not())
   })
})

虽然效果可能不是很好