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 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址