RethinkDB - 同时过滤和匹配

RethinkDB - Filtering and matching at the same time

您好,我是 RethinkDB 的新手,一般来说 javascript。我想知道使用多个过滤器(包括正则表达式匹配)执行查询的最佳方法是什么。

例如将这两个查询合并为一个查询,目的是在给定频道中查找以字符串 'test'

开头的所有消息
r.table('messages').filter({ 
  channel: 'channel_id' 
}).run(this._rdbConn)

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

除了答案之外,任何对参考有用的文档都将不胜感激。

编辑:我注意到您可以链接过滤器,但这是实现我想要做的事情的正确方法吗?

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

链接筛选器可能是执行所需操作的最简单方法。你也可以写 .filter(function(row) { return row('channel').eq('channel_id').and(row('text').match('^test')); }).