Main Content

neo4j

Connect to Neo4j database

Description

The neo4j function creates connections to a Neo4j® database. For relational database connections, see Connect to Database.

example

neo4jconn = neo4j(url,username,password) creates a Neo4jConnect object using the URL, user name, and password for the Neo4j database. Use the object to retrieve graph data from the Neo4j database.

Examples

collapse all

Create a Neo4j® database connection using the URL http://localhost:7474/db/data, user name neo4j, and password matlab.

url = 'http://localhost:7474/db/data';
username = 'neo4j';
password = 'matlab';

neo4jconn = neo4j(url,username,password)
neo4jconn = 
  Neo4jConnect with properties:

         URL: 'http://localhost:7474/db/data/'
    UserName: 'neo4j'
     Message: []

neo4j returns a Neo4jConnect object with these properties:

  • URL — The Neo4j database web location

  • UserName — The user name used to connect to the database

  • Message — Any database connection error messages

Check the Message property of the Neo4j connection object neo4jconn. The blank Message property indicates a successful Neo4j database connection.

neo4jconn.Message
ans =

     []

Retrieve all node labels using the Neo4j database connection neo4jconn. The cell array nlabels contains a character vector for the one node label in the Neo4j database.

nlabels = nodeLabels(neo4jconn)
nlabels = 1×1 cell array
    {'Person'}

Close the database connection.

close(neo4jconn)

Create a Neo4j® database connection using the Database Toolbox™ Interface for Neo4j Bolt Protocol. Use a Bolt protocol URL to connect to the Neo4j database.

Create a Neo4j database connection using the Bolt protocol URL bolt://localhost:7687/db/data, user name neo4j, and password matlab.

url = 'bolt://localhost:7687/db/data';
username = 'neo4j';
password = 'matlab';

neo4jconn = neo4j(url,username,password)
neo4jconn = 
  Neo4jConnect with properties:

         URL: 'bolt://localhost:7687/db/data'
    UserName: 'neo4j'
     Message: []

neo4j returns a Neo4jConnect object with these properties:

  • URL — The Neo4j database web location

  • UserName — The user name used to connect to the database

  • Message — Any database connection error messages

Check the Message property of the Neo4j connection object neo4jconn. The blank Message property indicates a successful Neo4j database connection.

neo4jconn.Message
ans =

     []

Retrieve all node labels using the Neo4j database connection neo4jconn. The cell array nlabels contains a character vector for the one node label in the Neo4j database.

nlabels = nodeLabels(neo4jconn)
nlabels = 1×1 cell array
    {'Person'}

Close the database connection.

close(neo4jconn)

Input Arguments

collapse all

Neo4j database connection URL that contains the server, port number, and web location of the Neo4j database, specified as a character vector or string scalar.

If you specify a URL that starts with the http:// protocol identifier, then the neo4j function uses the REST API to connect to the Neo4j database.

If you specify a Bolt database connection URL that starts with the bolt:// protocol identifier, that is, you use the Database Toolbox™ Interface for Neo4j Bolt Protocol, then the neo4j function creates a Bolt connection instead.

Note

Ensure that you use the correct port number in the Neo4j database connection URL when you use the Bolt protocol. The default port number 7687 for the Bolt protocol is different from the default port numbers 7474 and 7473 for the HTTP and HTTPS protocols, respectively.

If you specify any other protocol identifier, then the neo4j function uses the REST API to create the database connection.

Example: http://localhost:7474/db/data specifies using the HTTP protocol where localhost is the server, 7474 is the port number, and /db/data is the web location of the database.

Example: bolt://localhost:7687/db/data specifies using the Bolt protocol where localhost is the server, 7687 is the port number, and /db/data is the web location of the database.

Data Types: char | string

User name for accessing the Neo4j database, specified as a character vector or string scalar. If no database authentication is required, specify an empty character vector.

Data Types: char | string

Password for accessing the Neo4j database, specified as a character vector or string scalar. If no database authentication is required, specify an empty character vector or string scalar.

Data Types: char | string

Output Arguments

collapse all

Neo4j database connection, returned as a Neo4jConnect object.

Limitations

  • The REST API and Database Toolbox Interface for Neo4j Bolt Protocol do not support Neo4j database versions 4.0 and later.

Version History

Introduced in R2016b