1

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)
4

1 回答 1

0

链接过滤器可能是做你想做的最简单的方法。你也可以写.filter(function(row) { return row('channel').eq('channel_id').and(row('text').match('^test')); })

于 2016-08-01T08:07:55.427 回答