Loop function in neo4j

Hi everyone :relaxed:

How can I write a function in neo4j that takes each person's name as input and output that person's relationships with other people in different files?

Can you clarify your requirements so we can help?

  1. Do you really mean a neo4j function that runs on the server and you call via cypher, or do you mean how can you do this in native cypher?
  2. What do you mean by "in a different files?" Do you want to write the data to a file?
  3. Are you executing the cypher in desktop, or are you using a driver?

In the meantime, the following cypher will get all the people a person knows, where the people are provided in a list. Maybe this helps getting you started.

with ['John', 'Sally', 'Paul'] as names
unwind names as name
match (n:Person{name:name})-[:KNOWS]->(m)
return n as person, collect(m) as knows

Test Data:

Result: