AGupta
AGupta

Reputation: 5734

How to check array property in neo4j?

How to search node using cypher query where one of the node property having array of string ?
e.g. members-- > ["abc","xyz","pqr"].
I can find the node by keeping order of array elements in same manner, for e.g.

START root=node(*) where has(root.members) and root.members=["abc","xyz","pqr"] return root;

but How to search node if I do not / cannot provide the exact order of elements as they are in node property ?

Upvotes: 6

Views: 4302

Answers (1)

Lisa Li
Lisa Li

Reputation: 2592

Use the "all" predicate to ensure every element in the root.member is in the given list, i.e. root.members is a subset of the given list, and the length expression ensures that the given list has no more elements than what is in the root.members, so both of them contain the exactly same members.

START root=node(*)
Where has(root.members) and all ( m in root.members where m in ["abc","xyz","pqr"]) and length(root.members) = length(["abc","xyz","pqr"])
Return root

Upvotes: 9

Related Questions