I have the following params:
:params {
"properties1":[ {
"content":"some string",
"decoration": "xsd@string"
},
{
"content":"another string",
"decoration":"xsd@string",
}],
"properties2":[ {
"content":"more string",
"decoration": "xsd@string"
},
{
"content":"another string",
"decoration":"xsd@string",
}],
}
And the following query:
CREATE (A:SomeParent {uuid: "Parent"})
WITH A
CREATE (pro:SomeProperty { uuid: "ABCDEE" })
WITH A, pro
CREATE (A)-[:property]->(pro)
WITH A, pro // <- this is the startElement
// ----
UNWIND $properties1 AS properties // <--- this is
MERGE (v:SomeValue) SET v = properties // <--- all
MERGE (pro)-[:value]->(v) // <--- I require
// ----
WITH A
CREATE (pro:SomeProperty { uuid: "ABCDEF" })
WITH A, pro
CREATE (A)-[:property]->(pro)
WITH A, pro
// ----
UNWIND $properties2 AS properties // <--- this is
MERGE (v:SomeValue) SET v = properties // <--- all
MERGE (pro)-[:value]->(v) // <--- I require
// -----
And I am getting this output:
The issue why you only get one node of type SomeValue is that you are merging on this label without any constraints. As such, each time you perform a 'MERGE (v:SomeValue)
operation it is finding the first SomeValue you node created and updating it instead of creating a new one. The end result is that you end up with one SomeValue node with the properties of the last SET operation, which is the second element of your properties2 array.
In my previous code i was generating each SomeValue one by one, because I want them to be unique as <content,decoration> pairs across all my graph ... but now with the UNWIND I only get 1 SomeValue all together (instead of 3).
Change your merge statements to the following, then you will get unique SomeValue nodes based on those two properties. This will also set the properties, so you don't need the SET operations either.
MERGE (v:SomeValue{content:properties.content, decoration:properties.decoration})
1 Like
Fixed it, thank you very much, you're a star!
1 Like
Are you getting two of the (pro:SomeProperty { uuid: "ABCDEF" })
nodes? If so, it is because the result of the first unwind is to create two rows of the same value of 'A', thus the CREATE (pro:SomeProperty { uuid: "ABCDEF" })
gets executed twice. One fix is to change the preceding WITH to WITH DISTINCT A
. Another fix is to replace the UNWINDs with FOREACH clauses.
I don't create the SomeParent and SomeProperty in this statement - I only did the creates so it was an easy "copy/paste".
But I'll keep in mind if that happens when I test!