如何找到字段的值,其值与数组中的任何值相等。

huangapple go评论125阅读模式
英文:

How to find field's value whose equal any value in array

问题

我有一个包含一些ID的数组:

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

我想通过这个数组,找到所有具有"OriginID"的帖子,其中"OriginID"是表中存在的ID之一。

我已经开始了一些工作,但我不知道如何完成这段代码使其工作。

  1. curs, _ = r.Table("posts").
  2. Filter(r.Row.Field("Validated").Eq(false)).
  3. Filter(func(customer r.Term) interface{}{
  4. for _, id := range listOriginID {
  5. //我不知道如何完成
  6. }
  7. })

谢谢你的帮助。

英文:

I have an array whose contain some ID :

  1. ["4007fa1c-4e27-4d2e-9429-f3631171760c",
  2. "a21649a3-1a64-45cf-b92a-e899a7ef4742",
  3. "1903a571-b166-4f93-9c1c-93dc66067a49",
  4. "2845d278-5ec4-45e9-ab9c-999178332c73",
  5. "4e3ed481-a3d9-4689-8873-5c912668b26f",
  6. "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.

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

Thank you for your help

答案1

得分: 1

当你发现自己在 ReQL 查询中尝试迭代一个数组时,通常更容易或必要使用内置的 ReQL 操作,比如 MapConcatMap

在这种情况下,Contains 似乎是你想要的操作。尝试像这样的代码:

  1. (...).Filter(func(post r.Term) interface{}{
  2. r.Expr(listOriginID).Contains(post.Field("OriginID"))
  3. })
英文:

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:

  1. (...).Filter(func(post r.Term) interface{}{
  2. r.Expr(listOriginID).Contains(post.Field("OriginID"))
  3. })

huangapple
  • 本文由 发表于 2017年1月31日 03:16:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/41943744.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定