How do you execute a Cypher statement and access the results?
Execute the Cypher statement
Select the correct method to execute the Cypher statement.
driver = GraphDatabase.driver(NEO4J_URI,
    auth=(NEO4J_USER, NEO4J_PASSWORD)
)
cypher = """
MATCH (m:Movie {title: $title})<-[:ACTED_IN]-(p)
RETURN p.name AS actor
"""
params = {"title": "Toy Story"}
res, summary, keys = driver.#select:execute_query(
    cypher,
    **params
)- 
❏ cypher(
 - 
✓ execute_query(
 - 
❏ execute(
 - 
❏ verify_connectivity(
 
Hint
The method to execute a Cypher query with the driver is the same one you used in the previous lesson - it starts with execute_.
Solution
The correct answer is execute_query(). This method executes a Cypher query and returns the results.
driver.execute_query(cypher, **params)Print the actor names
Update the code to print the name of each actor.
for record in res.records:
    print(
        #select:record["actor"]
    )- 
❏ record["p.name"]
 - 
✓ record["actor"]
 - 
❏ record.get("actor")
 - 
❏ typeof(record).getActor()
 
Hint
Review the RETURN clause in the Cypher statement.
cypher = """
MATCH (m:Movie {title: $title})<-[:ACTED_IN]-(p)
RETURN p.name AS actor
"""Solution
The name property of the p node is aliased as actor in the RETURN clause.
for record in res.records:
    print(record["actor"])Lesson summary
Nice work! You learned how to execute a Cypher statement and access the results.
In the next lesson, you will review how to transform the results.