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.

How can I read the data after a tx.run?

geronimo4j
Graph Buddy

I'm getting started on the official driver, "neo4j" and I'm having trouble reading the results after a query.

I have this:

with self.driver.session() as session:
            greeting = session.write_transaction(self._create_and_return_thing, title)
            print(greeting)

    @staticmethod
    def _create_and_return_thing(tx, data):
        result = tx.run("CREATE (t:Thing) "
                        "SET t.name = $title "
                        "SET t.image = $image "
                        "SET t.description = $overview "
                        "SET t.release_date = $release_date "
                        "SET t.title = $title "
                        "SET t.id = randomUUID() "
                        "RETURN t", data),

And the data is successfully added to the database, but I can't figure out how to read "t" that returns from this.

I've tried a million combinations of the below:

 record = result.single()
  print(data.name, record["id"])
  for r in result:
       print("record: ", r['t.id'])
       print("record: ", result[r]['t.id'])
       return list(result)

None of these work^ and those are just what's left, have tried a million things and I can't figure out how to see the data, basically I want to get my hands on the "ID" returned from that create method.

1 REPLY 1

You return t so you need to use r["t"] which is a node type so you can then access it's id's

https://neo4j.com/docs/api/python-driver/current/api.html#node