Search code examples
rethinkdbin-subquerynosql

Filtering out results using sub-queries in ReQL/Rethink?


I'm am trying to learn more about RethinkDB and its sub-query abilities. I was wondering if the following would be possible in ReThinkDB:

// example of "post" document:
{ id: .., allow: [], disallow: [some_label_id, other_label_id], ... }

// example of "label" document:
{ id: .., user_id: .., name: 'my-label' }

var MY_USER_ID = "1b4-4c6-7d9"

// Query in psuedo-code:
IN database test
IN table posts   
FILTER out any "posts" where the "disallow" array
  contains a value found in this sub-query:
   IN table labels  
   FILTER id .eq disallow[index] AND user_id .eq MY_USER_ID

Solution

  • RethinkDB currently doesn't have intersect and contains commands. They'll be in the 1.4 release tentatively scheduled for April 15th.