neo4j
Connect to Neo4j database
Description
The neo4j
function creates connections
to a Neo4j® database. For relational database connections, see Connect to Database.
Examples
Connect to Neo4j Database
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 locationUserName
— The user name used to connect to the databaseMessage
— 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)
Connect to Neo4j Database Using Bolt Protocol
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 locationUserName
— The user name used to connect to the databaseMessage
— 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
url
— Neo4j database connection URL
character vector | string scalar
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
username
— User name
character vector | string scalar
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
— Password
character vector | string scalar
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
neo4jconn
— Neo4j database connection
Neo4jConnect
object
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
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)