How can I view the actual query that is sent from the neo4j-go driver?

I am working on a query that as far as I can tell should work. However, it's not. I need to see the actual query that's hitting neo4j. Is that possible? Currently using 4.4 - GitHub - neo4j/neo4j-go-driver: Neo4j Bolt Driver for Go with Bolt.

I don't have the enterprise version, so I don't have query logs.

Hello,

Since version 4.3 of the driver, you can actually get the driver logs of the protocol messages flowing in and out of the driver (in particular, the RUN message with the query that's being run to the server).

This logging is enabled on a per-session basis since it can be quite verbose.

Here is a working example:

package main

import (
	"fmt"
	"github.com/neo4j/neo4j-go-driver/v4/neo4j"
)

func main() {
	driver, err := neo4j.NewDriver("bolt://localhost", neo4j.BasicAuth("neo4j", "pass", ""))
	if err != nil {
		panic(err)
	}
	defer driver.Close()
	session := driver.NewSession(neo4j.SessionConfig{
		BoltLogger: neo4j.ConsoleBoltLogger(), // <--- enable Bolt logging to see RUN message with query
	})
	defer session.Close()
	result, err := session.ReadTransaction(countNodes)
	if err != nil {
		panic(err)
	}
	fmt.Printf("%v\n", result)
}

func countNodes(tx neo4j.Transaction) (interface{}, error) {
	result, err := tx.Run("MATCH (n) RETURN COUNT(n)", nil)
	if err != nil {
		return nil, err
	}
	single, err := result.Single()
	if err != nil {
		return nil, err
	}
	count, _ := single.Get("COUNT(n)")
	return count, nil
}

2 Likes