how do I filter rethinkdb table column (object array) based on 2 values

183 views Asked by At

I am trying to filter a rethinkdb table (conversations) which contains nested object array called participants. The structure is below.

I am trying to execute a query that selects conversations based on the IDs of the participants.

in plain terms I want to return all conversations where user 'A' with user_id equals 1 and user 'B' with user_id equals 2 are participants.

RETHINKDB DOCUMENT:Conversations

    [{
       id:'xxx',
       createdAt:'xxxxxx',
       participants:[
          {
            user_id:1,
            email:'xxxx',
            name:'xxxxxx'

          },
           {
            user_id:2,
            email:'xxxx',
            name:'xxxxxx'
          }
      ]
    }
   ]
1

There are 1 answers

0
Neo On

I did find this to work, from the documentation

r.table("conversations").filter((user)=>{
     return user("participants")("user_id").contains("userid1","userid2")
})