W4G1
W4G1

Reputation: 1694

How to connect using Neo4j driver over IPv6?

Is it possible to connect to a Neo4j or Memgraph database over IPv6? I am using the neo4j-driver javascript library but it seems that it is not able to parse a IPv6 connection string:

const driver = neo4j.driver("bolt://fdaa:0:a23f:a7b:c988:dd94:aff3:2:7687"); // Error: getaddrinfo ENOTFOUND fdaa

Upvotes: 0

Views: 320

Answers (3)

Andi Skrgat
Andi Skrgat

Reputation: 11

Actually, it will work with Memgraph too: add the brackets like mentioned and make sure that you start Memgraph with --bolt-address parameter set to ::. You can check here how to do this.

Upvotes: 1

Robsdedude
Robsdedude

Reputation: 1403

Try wrapping the IPv6 address in brackets like so

const driver = neo4j.driver("bolt://[fdaa:0:a23f:a7b:c988:dd94:aff3:2]:7687");

I'm not sure this will work with the JS driver, but this is how you would do it with the Neo4j Python driver.

Upvotes: 1

Josip Mrden
Josip Mrden

Reputation: 56

I tried it with Javascript but doesn't work for me neither. Probably neo4j's driver for Javascript doesn't support ipv6.

I found here https://community.neo4j.com/t5/neo4j-graph-platform/troubleshooting-connection-issues-to-neo4j/m-p/47959 that the possible solution could be setting the flag

dbms.connectors.default_listen_address=::1

but that possibly means only configuring the loopback address will be parsed from IPv6.

Memgraph reuses the Neo4J's Javascript driver so that won't work as well, but the GQLAlchemy which is able to connect to Memgraph does parse IPv6 without any problems, with the following code snippet:

from gqlalchemy import Memgraph

if __name__ == "__main__":
    memgraph = Memgraph(host='0:0:0:0:0:0:0:1', port=7687)

    memgraph.drop_database()
    
    memgraph.execute("CREATE (n);")
    result = next(memgraph.execute_and_fetch("MATCH (n) RETURN COUNT(n) as cnt;"))
    print(result['cnt'])

The only downside is, it is built in Python, which was not your preferred choice of language.

Upvotes: 1

Related Questions