cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Py2neo - How do i get node id by node matching

Hello, i'm using py2neo and try to get node id by these code
for rel in matcher.match("SINGLE_NODE"):
print("name:", rel["name"])
print("occur:", rel["occur"])
print("pos:", rel["pos"])

and there is no entity["id"], i want to know anyhow to get id of each node.
thank you

2 REPLIES 2

MuddyBootsCode
Graph Steward

I'm not sure about py2neo but it can sometimes be returned with _ID. If you've placed your own ID on a node you could something like:

MATCH (n:Person {id: yourID}) RETURN ID(n)

which would give you the Neo4j ID of your node

from py2neo import Graph
graph = Graph()
graph.run("MATCH (a:Person) RETURN a.name, a.id LIMIT 4").data()

or if you want only the auto generated node ID
node = graph.evaluate("MATCH (a:Person) RETURN a LIMIT 1")
node_id = node.identity

Some useful links
https://py2neo.org/v4/database.html