neo4jcypheragens-graph

Cypher relating many nodes to one node


Say I have all these objects in a graph:

5ffcedc70cc70
5ffd73259ad18
5ffd7394311bf
5ffd740fd836c
5ffd74b7001fe
5ffd746b3f457
5ffd74fc7d21d
5ffd75428691b
5ffd75f0509e0
5ffd7586a2916
5ffd789434539
5ffd78e65bae8
5ffd794fcb91a

And I want to relate them to a single node:

David

Singularly I'd:

MATCH (a:Object),(b:Person)
WHERE a.name = '5ffdbb309d9a6' AND b.name = 'David'
CREATE (a)-[r:CREATEDBY]->(b);

Is there anyway to loop through a list of objects so I can say (Object)-[CREATEDBY]->(David)


Solution

  • I think what you need is a simple IN clause, https://neo4j.com/docs/cypher-manual/current/clauses/where/#where-in-operator

    MATCH (a:Object),(b:Person)
    WHERE a.name IN ['5ffdbb309d9a6', '5ffd73259ad18' ...] AND b.name = 'David'
    CREATE (a)-[r:CREATEDBY]->(b);
    

    or am i missing something?