Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
09-01-2021 09:50 AM
Neo4j Desktop version: 1.4.7
Database version: 4.3.1
Driver version: 4.3.4
Hi all,
I'm trying to get...well, any results from my database so far and nothing is coming back. My write_transaction of a works but read_transaction with even a basic query gives nothing, but the same query works fine in the Neo4j browser.
def find_nodes(tx):
result = tx.run("MATCH (n) RETURN n LIMIT 25")
return result
with driver.session(database="cophrdf") as session:
nodes = session.read_transaction(find_nodes)
for row in nodes:
print(row)
I get no output from this.
Thanks in advance for any help!
Daniel
Solved! Go to Solution.
09-02-2021 02:47 AM
def test_query(tx):
query = "MATCH (p) RETURN p LIMIT 25"
result = tx.run(query)
return [row["p"] for row in result]
with driver.session() as session:
query_result = session.read_transaction(test_query)
for node in query_result:
print(f"Node {list(node.labels)} {dict(node)}")
Works for me. 4.3.4 driver with a 4.3.2 neo4j server. Make sure there are actually nodes in your database.
09-01-2021 02:17 PM
Try using result.data()
Read about result objects here:
https://neo4j.com/docs/api/python-driver/current/api.html#neo4j.Result
09-01-2021 03:32 PM
Hi Andre,
Thanks very much for the quick response!
I've also played around with result.data() and unfortunately I get an empty dictionary. Here is the test I did:
def test_query(tx):
data = {}
query = ("MATCH (p) RETURN p LIMIT 25")
result = tx.run(query)
for key, value in result.data():
data[key] = value
return data
with driver.session() as session:
query_result = session.read_transaction(test_query)
for key, value in query_result.items():
print(f"{key}: {value}")
result.keys() gives me 'p' and result.values() is empty.
09-02-2021 02:47 AM
def test_query(tx):
query = "MATCH (p) RETURN p LIMIT 25"
result = tx.run(query)
return [row["p"] for row in result]
with driver.session() as session:
query_result = session.read_transaction(test_query)
for node in query_result:
print(f"Node {list(node.labels)} {dict(node)}")
Works for me. 4.3.4 driver with a 4.3.2 neo4j server. Make sure there are actually nodes in your database.
09-02-2021 06:45 AM
Hi again all,
I don't know what changed with the update but after updating my Desktop and Browser versions it suddenly works with both my data test and your code rouven.bauer. My original code still doesn't but I'm going to assume that's me still trying to figure out what's going on here.
Thanks for the replies guys!
09-02-2021 06:47 AM
Your original code doesn't work because the result goes out of scope when the function (and with it the transaction) ends.
Happy to hear you've got it working.
All the sessions of the conference are now available online