rethinkdb如何检查一个序列是否包含另一个序列的任何元素?

How to check whether a sequence contains any element of another sequence in rethinkdb?

我知道 "contains" 会检查一个序列是否包含另一个序列的所有元素 sequence.I 想知道:

Is there any simple way to check whether a sequence contains any element of another sequence?

更新: 我不想检查 A 是否包含 B 的所有元素,而是 B 的任何一个元素。

如果你想检查某个序列 seq 是否包含另一个序列 test_seq 的所有元素,我会使用 set_difference

test_seq.setDifference(seq).isEmpty().not()

如果 seq 非常大(比如映射到 table 的结果),您只能使用 reduce:

有效地做到这一点
seq.map(function(row) {
  return test_seq.setIntersection([row])
}).reduce(function(a, b) {
  return a.setUnion(b);
}).count().eq(test_seq.count())

你可以试试do with difference.

例如,您有 table MyTable,其中 MyArray 包含字符串数组。

r.table("MyTable").get("my_id").do(
    function (record) {
        return record('MyArray').difference(["something1", "something2"]).count().ne(record('MyArray').count()
          )
    }
)

如果字段 MyArray 包含 ["something1"、"something2"] 的任何元素,它将 return true。否则 - false