Aman
Aman

Reputation: 3261

How to add multiple value for a relationship properties in neo4j?

I want to add multiple value for a single relationship properties.
just like below..
I have a relation is "CALLED" which is bidirectional.I want to have two value for "DURATION" like DURATION (100-200->500,200-100->600) enter image description here

Can I put two values for a single proeprties??

Upvotes: 3

Views: 509

Answers (1)

Stefan Armbruster
Stefan Armbruster

Reputation: 39905

You can use a property having an array of Strings as value:

MERGE (a:Person{number:'123'})
MERGE (b:Person{number:'456'})
MERGE (a)-[r:CALLED]->(b)
ON CREATE SET r.duration = ["100-200->500"]
ON MATCH SET r.duration = ["100-200->500"]

Later on when adding the second duration value, use

MERGE (a:Person{number:'123'})
MERGE (b:Person{number:'456'})
MERGE (a)-[r:CALLED]->(b)
ON MATCH SET r.duration = n.duration + "200-100->600"

N.B. the "+" operator on an array amends a new element to the array.

Upvotes: 5

Related Questions