0
votes

(http://neo4j.com/docs/developer-manual/current/cypher/clauses/create-unique/)

Am I correct that it could be used to create various relationships between two constant nodes (i.e. there are many relationships between two same nodes) with different values in their properties?

Is it possible to have such a command?

Load CSV from ...
MATCH (sender:Wallet {primWallAddr:line[0]}), (receiver:Wallet {primWallAddr:line[1]}) 
CREATE UNIQUE (sender)-[:SendTo{tranHashString:line[2],...uniqueReference:(line[2])}]->(receiver)")

Is it possible to use "MERGE" instead of "CREATE UNIQUE" to achieve the same result? If not, why?

1

1 Answers

2
votes

It is possible to use MERGE instead of CREATE UNIQUE, perhaps even preferred. What you need to do is to MERGE by uniqueReference like so:

Load CSV from ...
MATCH (sender:Wallet {primWallAddr:line[0]}), (receiver:Wallet {primWallAddr:line[1]}) 
MERGE (sender)-[:SendTo{tranHashString:line[2],...uniqueReference:(line[2])}]->(receiver)

Slightly more optimized would be MERGEon unique reference and set additional properties with ON CREATE

Load CSV from ...
MATCH (sender:Wallet {primWallAddr:line[0]}), (receiver:Wallet {primWallAddr:line[1]}) 
MERGE (sender)-[s:SendTo{uniqueReference: line[2]]->(receiver)
ON CREATE SET s.tranHashString = line[3]

If you wanted to have only one relationship between this sender and receiver and just update its properties you would use:

Load CSV from ...
MATCH (sender:Wallet {primWallAddr:line[0]}), (receiver:Wallet {primWallAddr:line[1]}) 
MERGE (sender)-[s:SendTo]->(receiver)
ON CREATE SET s.tranHashString = line[3]
ON MATCH SET s.tranHashString = line[3]

Answer to question 1 :

Yes from what I understand you can use CREATE UNIQUE in your case, just know that if you want to change any property of the relationship, CREATE UNIQUE will create a new relationship and never update existing, which will ruin your ID system.