duan2477 2017-05-16 08:02
浏览 27
已采纳

为什么.Filter(func())中的Contains在gorethink中不起作用并且部分查询被忽略?

I am trying to do this:

r.table(table).filter(
  function (doc) {
    return r.expr(array)
            .contains(doc("name"));
  }
)

written in golang that is

rethink.Table(table).GetAllByIndex(index, value).Filter(func(row rethink.Term) interface {}{

    return rethink.Expr([]string{}).Contains(row.Field("type"))
})

I am not sure but it is like rethink.Expr is ignored. That is first problem.

Second problem is next. If I have query written like this:

query := rethink.Table(table).GetAllByIndex(index, value)

and then try to do next:

if some_condition {
   q.Filter(some_filter)
}

if some_other_condition {
   q.Filter(some_other_filter)
}

when i print out q.String() i got only that first part and everything else is ignored rethink.Table(table).GetAllByIndex(index, value)

  • 写回答

1条回答 默认 最新

  • dqsk4643 2017-05-16 11:39
    关注

    Since the Filter method returns a new Term, which will contain the expression of the previous term, you need to re-assing the result back to q.

    if some_condition {
       q = q.Filter(some_filter)
    }
    
    if some_other_condition {
       q = q.Filter(some_other_filter)
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)