Aleksandrenko
Aleksandrenko

Reputation: 3063

How to get node's id with cypher request?

I'm using neo4j and making executing this query:

MATCH (n:Person) RETURN n.name LIMIT 5

I'm getting the names but i need the ids too. Please help!

Upvotes: 31

Views: 30495

Answers (4)

HyperActive
HyperActive

Reputation: 1328

In 2024

MATCH (n:Person) RETURN elementId(n) LIMIT 5

as per https://neo4j.com/docs/cypher-manual/current/functions/scalar/#functions-elementid

Upvotes: 0

e.upton
e.upton

Reputation: 62

Not sure how helpful or relevant this is, but when I'm using the NodeJS API the record objects returned from Cypher queries have an identity field on the same level as the properties object (e.g record.get(0).properties, record.get(0).identity). I'm assuming you aren't just doing plain Cypher queries and actually using a driver to send the queries - so you might not have to run another MATCH statement.

I'm aware that the OP is asking about Cypher specifically - but it might be helpful to other users that stumble upon this question.

Upvotes: 3

Marcus.D
Marcus.D

Reputation: 769

Or you can take a look on the Neo4j Cypher Refcard

You can get a short look to a lots of functions and patterns you can write.

And more about functions on The Neo4j Developer Manual - Chapter 3. Cypher - 3.4. Functions

Upvotes: 0

subvertallchris
subvertallchris

Reputation: 5482

Since ID isn't a property, it's returned using the ID function.

MATCH (n:Person) RETURN ID(n) LIMIT 5

Upvotes: 62

Related Questions