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 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.

  • Go
1 ACCEPTED SOLUTION

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
}

View solution in original post

1 REPLY 1

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
}