0

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'
          }
      ]
    }
   ]
Michael Armes
  • 1,056
  • 2
  • 17
  • 31
Neo
  • 717
  • 2
  • 11
  • 26

1 Answers1

0

I did find this to work, from the documentation

r.table("conversations").filter((user)=>{
     return user("participants")("user_id").contains("userid1","userid2")
})
Neo
  • 717
  • 2
  • 11
  • 26