Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
02-04-2022 03:34 PM
with driver.session() as session:
result = session.run("MATCH(n) RETURN n")
return result
this result object is containing no data when tried to use in different function as an iterator but it works within same function. I am not sure if i am thinking or doing something wrong. please help me solve this
02-06-2022 12:16 AM
Can you explain in detail what exactly you are trying to accomplish?
02-06-2022 01:50 AM
I want to use returned variable "result" in some other function like
for record in result:
print(record)
02-06-2022 01:53 AM
Hello @sandeepkrjha1999 and welcome to the Neo4j community
def bolt_to_list(result):
"""
Function to transform BOLT result into list of dictionnaries.
"""
return [r.data() for r in result]
So you can use this function like this:
with driver.session() as session:
result = bolt_to_list(session.run("MATCH(n) RETURN n"))
return result
Regards,
Cobra
02-06-2022 09:35 AM
even with this approach you are storing all results in a list at once in the memory, i don't want to do that, I want that i can use it as an iterator for accessing records one by one without storing it in any list.
Basically what i mean to say is I want to return the bolt type and then use it in some other function for accessing the records from the bolt iterator
02-06-2022 04:28 PM
The session is closed and resources released once leaving the 'with' clause. You need to consume the resource before leaving the with clause. You could call your print statement before returning.
02-07-2022 04:19 AM
Yes, if you want to iterate over the records one by one, you cannot close the session before you are done. What you could do it something like this:
with driver.session() as session:
result = session.run("MATCH(n) RETURN n")
for record in result:
do_something_with_the_record(record)
All the sessions of the conference are now available online