millejo3
millejo3

Reputation: 13

RethinkDB - Filtering and matching at the same time

Hello I'm new to RethinkDB and javascript in general. I was wondering what the best way is to perform a query with multiple filters including a regex match.

e.g. merge these two queries into one with the goal of finding all messages in a given channel that start with the string 'test'

r.table('messages').filter({ 
  channel: 'channel_id' 
}).run(this._rdbConn)

r.table('messages').filter(r.row('text').match('^test').run(this._rdbConn)

Any documentation that would be useful to reference in addition to an answer would be appreciated.

Edit: I noticed that you can chain filters, but is that a correct way of achieving what I'm trying to do?

r.table('messages').filter({ 
  channel: 'channel_id' 
}).filter(r.row('text').match('^test')).run(this._rdbConn)

Upvotes: 1

Views: 66

Answers (1)

mlucy
mlucy

Reputation: 5289

Chaining filters is probably the easiest way to do what you want. You could also write .filter(function(row) { return row('channel').eq('channel_id').and(row('text').match('^test')); }).

Upvotes: 0

Related Questions