cancel
Showing results for 
Search instead for 
Did you mean: 

Py2neo - How do i get node id by node matching

Kaowrg
Node

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

ganesh_sharma67
Node Clone

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

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.