Creating a Driver Instance

Your challenge is to add a new driver instance to an existing file with the connection details provided. Once you have created the driver, you will need to open a new session and execute a Cypher statement to find the director of the movie Toy Story.

Open Challenge in an Online IDE →

Steps

  1. Install the Neo4j Go Driver in the integrated terminal window

  2. Import the github.com/neo4j/neo4j-go-driver/v5/neo4j symbol and use the neo4j object to create a new instance of the Driver with Uri, Username and Password credentials provided obtained using the GetNeo4jCredentials() method

  3. Once you have created the Driver, open a new session and execute the following cypher statement using the params map.

    cypher
    Find the Director
    MATCH (p:Person)-[:DIRECTED]->(:Movie {title: $title})
    RETURN p.name AS Director
  4. To find the answer, click the Debug icon to the left of the IDE window and run Create Driver Challenge task, or use the integrated terminal window to run the following command:

    sh
    Run The Challenge
    go run pkg/challenges/create_driver/challenge.go
  5. Once you have the result, copy and paste it into the text box below and click Check Answer.

Your Answer

Who directed Toy Story?

Take the Director value output from the statement above and paste it into the box below.

  • ✓ John Lasseter

Hint

You need to call the neo4j.NewDriverWithContext() object to create a Driver instance using the Uri, Username and Password variables provided by the GetNeo4jCredentials() function, then open a new session, execute the Cypher statement and log the Director value of the first record.

Once you have a result object, use the neo4j.SingleTWithContext() function to extract the Director value from the first record.

Your fmt.Println() call should look similar to the code block below:

ts
fmt.Println(director)

Copy the answer without any quotes or whitespace.

Solution

John Lasseter directed Toy Story.

You can compare your code with the solution here.

go
Unresolved directive in questions/1-director.adoc - include::https://raw.githubusercontent.com/neo4j-graphacademy/app-nodejs/main/pkg/challenges/create_driver/solution/solution.go[]

Click here to view the solution.

Lesson Summary

In this challenge, you used your knowledge to create a driver instance and execute a Cypher statement.

In the next lesson, you will learn about the different transaction functions and when to use them.

Chatbot

Hi, I am an Educational Learning Assistant for Intelligent Network Exploration. You can call me E.L.A.I.N.E.

How can I help you today?