RethinkDB: LIKE Example

RethinkDB queries let you filter on column results using a regular expression match. You can do something very similar to “LIKE”, like so:

r.db('test')
 .table('users')
 .filter( (doc) => doc('user_name').match("test") )

SQL LIKE also treats “_” as any letter – so to reproduce this behavior, you’d need to use a period instead:

r.db('test')
 .table('users')
  .filter( (doc) => doc('user_name').match("t.st") )

If you want to make this case insensitive, you’ll also want to lowercase the table data:

r.db('test')
 .table('users')
  .filter( (doc) => doc('user_name').downcase().match("t.st") )
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 2
a86e769d-32fa-4853-9018-f8c360795304
test 2
test 2
5
test 9
1e1f4b1c-9d72-4473-b997-dfc545bec253
test 9
test 9
6
test 10
edabe8a9-b77e-4446-97aa-be9b7d542784
test 10
test 10
7
test 1
02b2fa2b-7e50-43cc-a476-a14d3b4324ac
test 1
test
8
test 7
d6503bb3-3e85-464e-9019-5beee03d1d9d
test 7
test 7
9
test 3
bfff0d26-f1f1-4a07-9bb6-e54302c5ee05
test 3
test 3
10
test 4
d6c17523-8857-44c4-a014-12ac58764276
test 4
test 4
11
test
cb93de7e-2d91-48ce-956e-4090694e5cb9
test
test

Leave a Reply

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