【问题标题】:RethinkDB: merge and then filter in queryRethinkDB:​​在查询中合并然后过滤
【发布时间】:2015-07-05 21:27:27
【问题描述】:

举个例子

r .table('posts')
  .get(100)
  .merge(function (post) {
    return {
        comments: r.table('comments').getAll(post('id'),
            {index: 'postId'}).coerceTo('array')
    }
 })
 .pluck({"comments": ["id", "created_on"]});

如何进一步过滤 cmets 以仅返回给定博客文章中特定用户的 cmets。 IE。获取博文 100 并通过 user_name == 'darth' 返回其 cmets

非常感谢提示

【问题讨论】:

    标签: rethinkdb


    【解决方案1】:

    终于有了以下结果:

    r
     .table('posts')
     .get(100)
     .merge(function (post) {
      return {
       comments: r
        .table('comments')
        .getAll(post('id'), {index: 'postId'})
        .coerceTo('array')
        .filter(function (row) {
         return r.expr(['darth', 'luke', 'chewey']).contains(row('user_name'));
        })
      }
     })
     .pluck({"comments": ["id", "user_name", "created_on"]});
    

    【讨论】:

      猜你喜欢
      • 2019-10-04
      • 2017-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多