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"))
    })
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?