Reputation: 5
I'm having trouble with lists in neo4j. I need to go through a list and compare each element with a property of another node. I tried something like this
MATCH (C:Courses),(S:Student)
WHERE
C.courseid = "8" AND
S.userid = FOREACH(l IN SPLIT(C.students,",")
CREATE (C)<-[E:enrolled]-(S)
RETURN E
where C.students
is a string of values separated with ",". FOREACH
was the only function that I found to do this, but I don't think I can use it that way. Any ideas of how I can do that?
Upvotes: 0
Views: 44
Reputation: 67019
This query should do what you intended:
MATCH (c:Courses)
WHERE c.courseid = '8'
MATCH (s:Student)
WHERE s.userid IN SPLIT(c.students, ',')
CREATE (c)<-[e:enrolled]-(s)
RETURN e
If you have a significant number of courses or students, then you should also create indexes for :Courses(courseid)
and/or :Student(userid)
.
Upvotes: 1