I want to execute several queries at the same time on the browser console, here are my requests :
CREATE (newNode1:NEW_NODE)
CREATE (newNode2:NEW_NODE)
MATCH (n1:LABEL_1 {id: "node1"}) CREATE (newNode1)-[:LINKED_TO]->(n1)
MATCH (n2:LABEL_2 {id: "node2"}) CREATE (newNode2)-[:LINKED_TO]->(n2)
When I execute them one by one there is no problem, but when I execute them at the same time, I get the following error : WITH is required between CREATE and MATCH
Is there any way to correct this?
The WITH clause allows query parts to be chained together, piping the results from one to be used as starting points or criteria in the next. It is important to note that WITH affects variables in scope. Any variables not included in the WITH clause are not carried over to the rest of the query.
To create a relationship between two nodes, we first get the two nodes. Once the nodes are loaded, we simply create a relationship between them. The created relationship is returned by the query.
An OPTIONAL MATCH matches patterns against your graph database, just like a MATCH does. The difference is that if no matches are found, OPTIONAL MATCH will use a null for missing parts of the pattern. OPTIONAL MATCH could be considered the Cypher equivalent of the outer join in SQL.
The MATCH clause allows you to specify the patterns Neo4j will search for in the database. This is the primary way of getting data into the current set of bindings. It is worth reading up more on the specification of the patterns themselves in Patterns.
Add a couple of WITHs?
CREATE (newNode1:NEW_NODE)
CREATE (newNode2:NEW_NODE)
WITH newNode1, newNode2
MATCH (n1:LABEL_1 {id: "node1"})
CREATE (newNode1)-[:LINKED_TO]->(n1)
WITH newNode1, newNode2
MATCH (n2:LABEL_2 {id: "node2"})
CREATE (newNode2)-[:LINKED_TO]->(n2)
Alternatively, you could do it in a different order and avoid the WITHs, the difference being that it won't create anything if n1/n2 don't MATCH.
MATCH (n1:LABEL_1 { id: "node1" })
MATCH (n2:LABEL_2 { id: "node2" })
CREATE (newNode1:NEW_NODE)-[:LINKED_TO]->(n1)
CREATE (newNode2:NEW_NODE)-[:LINKED_TO]->(n2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With