RethinkDB: NOT IN example

If you write a filter on a RethinkDB table, you can negate the filter with a not predicate:

r.db('test')
 .table('users')
  .filter( 
    (doc) => 
      r.expr(['test 1', 'test 2'])
       .contains(
         doc('user_name')
       ).not() 
  )

This logic is almost exactly backwards from SQL, where a query looks like “user_name NOT IN (‘test 1’, ‘test 2’)” – in RethinkDB you start with the array, and work backwards.

In our test database, this returns the following:

first_name
id
last_name
user_name
1
test 6
a31dd384-cd63-44c8-addd-cb81db15e278
test 6
test 6
2
test 5
3e9345bf-a16b-4bcd-927f-0ff226bf3228
test 5
test 5
3
test 8
d83d84fb-88e6-413a-8f13-742f77bed5c5
test 8
test 8
4
test 9
1e1f4b1c-9d72-4473-b997-dfc545bec253
test 9
test 9
5
test 10
edabe8a9-b77e-4446-97aa-be9b7d542784
test 10
test 10
6
test 1
02b2fa2b-7e50-43cc-a476-a14d3b4324ac
test 1
test
7
test 7
d6503bb3-3e85-464e-9019-5beee03d1d9d
test 7
test 7
8
test 3
bfff0d26-f1f1-4a07-9bb6-e54302c5ee05
test 3
test 3
9
test 4
d6c17523-8857-44c4-a014-12ac58764276
test 4
test 4
10
test
cb93de7e-2d91-48ce-956e-4090694e5cb9
test
test

Leave a Reply

Your email address will not be published. Required fields are marked *