我有一个案例,我必须使用cypher比较集合中的所有元素与另一个集合,以查看项目是否相等(忽略元素的顺序)。我最终写下了像下面这样的密码
MATCH(用户:用户)WHERE all(condition0 IN [“admin”,“user”] WHERE condition0 IN ['admin','readonly'])返回用户。
上述查询肯定是错误的,但我正在尝试查看其他替代方案,通过这些方法我可以形成查询以实现结果。
答案 0 :(得分:4)
您可以使用=
运算符:
return [1,2,3] = [1,2,3] //true
return [1,2,3] = [1,2] // false
return [1,2,3] = [3,2,1] // false
=
还检查两个集合是否完全相同。要忽略排序,您需要在使用UNWIND
和ORDER BY
的组合之前对两个集合进行排序:
with [1,2,3] as coll1, [3,2,1] as coll2
unwind coll1 as c // sort coll1
with c order by c, coll2
with collect(c) as coll1s, coll2
unwind coll2 as c // sort coll2
with coll1s, c order by c
with coll1s, collect(c) as coll2s
return coll1s = coll2s