douzhi19900102 2017-01-30 19:16
浏览 95
已采纳

如何查找等于数组中任何值的字段值

I have an array whose contain some ID :

["4007fa1c-4e27-4d2e-9429-f3631171760c",
"a21649a3-1a64-45cf-b92a-e899a7ef4742",
"1903a571-b166-4f93-9c1c-93dc66067a49", 
"2845d278-5ec4-45e9-ab9c-999178332c73",
"4e3ed481-a3d9-4689-8873-5c912668b26f",
"390e89fd-d680-4264-8806-8295b361d2f1"]

I would like thanks to this array, find all the posts having for "OriginID", one of the Ids present in the table.

I've started something like that, but I don't know how to complete to make work this code.

curs, _ =   r.Table("posts").
            Filter(r.Row.Field("Validated").Eq(false)).
Filter(func(customer r.Term) interface{}{
    for _, id := range listOriginID {
        //I don't know how to finish
    }
})

Thank you for your help

  • 写回答

1条回答 默认 最新

  • dongtou2097 2017-01-31 06:10
    关注

    When you find yourself trying to iterate over an array inside a ReQL query, it is often easier or necessary to use built-in ReQL operations such as Map or ConcatMap.

    In this case, Contains seems to be the operation you want. Try something like:

    (...).Filter(func(post r.Term) interface{}{
        r.Expr(listOriginID).Contains(post.Field("OriginID"))
    })
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮