Go is one of the Neo4j supported languages and an official driver is provided. Official drivers connect to the databases using BOLT protocol (HTTP is not available).

🚧

The 4.0 release of the official Go driver is not available and there is currently no release date available. The following article is about the 1.7 version of this driver, built for Neo4j 3.x.

📘

About connection parameters

We've used test credentials for all the following examples. Please replace them with your real connection parameters.

You'll find all the required information to connect to your database on our admin panel if you navigate to the Connection section. More on connecting to your database here

This section is intended to provide a small working example to connect to a GrapheneDB database using the Go driver. To get more detailed information, visit the driver web page: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/neo4j

📘

Bolt protocol is available in 3.0.0 or higher versions of Neo4j. You can check your Neo4j version if you navigate to the Overview page of your database.

A C connector called seabolt is needed to get the driver running. Please, find more information about how to install it at https://github.com/neo4j-drivers/seabolt

You can install the latest version of the driver using go get or dep commands:

$ go get github.com/neo4j/neo4j-go-driver

or

$ dep ensure github.com/neo4j/neo4j-go-driver

📘

Check the driver releases for the newest driver version available.

Setting up the connection:

var (
    driver neo4j.Driver
    session neo4j.Session
    result neo4j.Result
    err error
)

if driver, err = neo4j.NewDriver("bolt://db-jidgsytyxo1r31sd4ker.graphenedb.com:24786", neo4j.BasicAuth("admin", "b.P0shGn2gvpUD.9RAHyuY4QXkkUK7w", "")); err != nil {
    return err // handle error
}
defer driver.Close()

You can test the connection by running a simple query of the Movies dataset example:

if session, err = driver.Session(neo4j.AccessModeRead); err != nil {
      return err
}
defer session.Close()

Result, err = session.Run("MATCH (:Person {name: 'Tom Hanks'})-[:ACTED_IN]->(tomHanksMovies) RETURN movies")

if err != nil {
      return err
}

for result.Next() {
      fmt.Printf(result.Record().Get("movies"))
}

If err = result.Err(); err != nil {
      return err
}

Updated 2 months ago

Go


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.