Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Neo4J – How to retrieve START_ID, END_ID and ID from a relationship?

If I query a relationship in my database like below

MATCH (n)-[t]-[n] RETURN t

I get the following output:

{
  "identity": 423006861,
  "start": 89091471,
  "end": 278664,
  "type": "RELATION",
  "properties": {
     "value": 7.0
  }
}

How can I access the identity, start, end and type values?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

[...] RETURN t.start just gives me null which is clearly not right…

I have the feeling that only the properties part can be accessed. Is this true? What am I doing wrong?

>Solution :

The following functions are available on relationships :

  • startNode()
  • endNode()
  • id()

So,

MATCH (n)-[t]-[n]
RETURN
id(startNode(t)) AS startNodeId,
id(endNode(t)) AS endNodeId,
id(t) AS relationshipId
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading