How To Store Data In Neo4j Relationship

Posted By Vipul Pandey | 16-Mar-2018

Neo4j is a graph database which stores data in connected form in nodes and relationship as well. The main benefit of storing data in relationship It allows your queries to execute effictively and  quickly& minimizes the DB storage needed.

To store the data in relationship lets take an example and we will create 2 nodes in neo4j with the below sytax.

match(u:UserTest{name:'vipul'})
match(address:Address{houseNumber:12,Street:5})
create(u)-[relation:LIVES_AT]->(address)
set relation.from='12-2-2017'
return u,address

If we want to store multiple properties we can set by adding multiple properties in the same manner as :

match(u:UserTest{name:'vipul'})
match(address:Address{houseNumber:12,Street:5})
create(u)-[relation:LIVES_AT]->(address)
set relation.type_of_address='PERMANENT',relation.from='BY_BIRTH'

To check the stored data  we can use maltch statement of neo4j as described below.

match(u:UserTest{name:'vipul'})
match(address:Address{houseNumber:12,Street:5})
match(u)-[rel:LIVES_AT]-(a)
return rel

if your data contains successfu match ,It will show the following properties:

{
  "type_of_address": "PERMANENT",
  "dateOfBirth": "a"
}

Request for Proposal

Recaptcha is required.

Sending message..