Is there a way to iterate through every node in a neo4j database using py2neo?
My first thought was iterating through GraphDatabaseService
, but that didn't work. If there isn't a way to do it with py2neo, is there another python interface that would let me?
Edit: I'm accepting @Nicholas's answer for now, but I'll update it if someone can give me a way that returns a generator.
I would suggest doing that with asynchronous Cypher, something like:
from py2neo import neo4j, cypher
graph_db = neo4j.GraphDatabaseService()
def handle_row(row):
node = row[0]
# do something with `node` here
cypher.execute(graph_db, "START z=node(*) RETURN z", row_handler=handle_row)
Of course you might want to exclude the reference node or otherwise tweak the query.
Nige
One of two solutions come to mind. Either do a cypher query
START n=node(*) return n
The other, and I'm not familiar with python so I'm going to give the example in Java is
GlobalGraphOperations.at(graphDatabaseService).getAllNodes()
which is the way the the old deprecated graphDatabaseService.getAllNodes()
recommends.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With