Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 319
A Gupta Avatar asked Oct 01 '13 14:10

A Gupta


1 Answers

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
like image 181
Lisa Li Avatar answered Nov 10 '22 13:11

Lisa Li