英文:
How to find field's value whose equal any value in array
问题
我有一个包含一些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"]
我想通过这个数组,找到所有具有"OriginID"的帖子,其中"OriginID"是表中存在的ID之一。
我已经开始了一些工作,但我不知道如何完成这段代码使其工作。
curs, _ = r.Table("posts").
Filter(r.Row.Field("Validated").Eq(false)).
Filter(func(customer r.Term) interface{}{
for _, id := range listOriginID {
//我不知道如何完成
}
})
谢谢你的帮助。
英文:
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
得分: 1
当你发现自己在 ReQL 查询中尝试迭代一个数组时,通常更容易或必要使用内置的 ReQL 操作,比如 Map
或 ConcatMap
。
在这种情况下,Contains
似乎是你想要的操作。尝试像这样的代码:
(...).Filter(func(post r.Term) interface{}{
r.Expr(listOriginID).Contains(post.Field("OriginID"))
})
英文:
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"))
})
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论