Showing results for 
Search instead for 
Did you mean: 

Head's Up! Site migration is underway. Phase 2: migrate recent content

Multiple MERGE statements for different nodes copied to desktop browser- what is the trick to it?

There are examples of creating multiple nodes

(:Person {name: 'Michael Caine', born: 1933}),
(:Person {name: 'Liam Neeson', born: 1952}),
(:Person {name: 'Katie Holmes', born: 1978}),
(:Person {name: 'Benjamin Melniker', born: 1913})

in the "Creating Data" section and if you put this into the desktop browser the code will run,

but I have yet to figure out what the equivalent MERGE statements need to be to create relationships across different nodes.

MATCH (p:Person), (m:Movie) WHERE m.title = 'Batman Begins' AND ENDS WITH 'Caine' MERGE (p)-[:ACTED_IN]->(m)

If I copy multiple merge statements like the CREATE statement above an error message is returned.
How do I list a whole lot of MERGE commands for different nodes?

Please be patient- just learning baby steps.


With CREATE, you can create multiple nodes and relationships. With MERGE, you can only create one node or set of nodes with their respective relationships.

To perform MERGE, you must either provide enough information for the node to be able to create it (for example a property value that perhaps has a uniqueness index on it), or it must have a reference from a previous MATCH statement.

So, for example, you can create the node and then use MERGE to add the relationships:

CREATE (p:Person {name: 'xxx'}),
(m:Movie {title: 'yyy'})
MERGE (p)-[:ACTED_IN]->(m)
MERGE (p)-[:DIRECTED]->(m)