createNode
Create nodes in Neo4j database
Description
createNode(
creates a single
node without labels and properties by using a Neo4j® database connection.neo4jconn
)
createNode(
creates a single node or multiple nodes and returns node information by specifying
additional options using one or more name-value pair arguments. For example,
neo4jconn
,Name,Value
)'Labels','Person'
creates a node with the label
Person
.
Examples
Create Single Node
Create a single node in a Neo4j® database and display the contents of the node.
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);
Check the Message
property of the Neo4j connection object neo4jconn
. The blank Message
property indicates a successful connection.
neo4jconn.Message
ans = []
Create a single node in the database using the Neo4j database connection.
createNode(neo4jconn)
When you execute the createNode
function without any arguments except the Neo4j database connection, the function creates a single node without labels and properties.
Close the database connection.
close(neo4jconn)
Create Single Node with Label
Create a single node with a label in a Neo4j® database and access the node.
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);
Check the Message
property of the Neo4j connection object neo4jconn
. The blank Message
property indicates a successful connection.
neo4jconn.Message
ans = []
Create a single node with a label in the database by using the Neo4j database connection. Use the 'Labels'
name-value pair argument to specify the label Scientist
.
label = 'Scientist'; createNode(neo4jconn,'Labels',label)
Search for the new node using the label Scientist
.
nodeinfo = searchNode(neo4jconn,label)
nodeinfo = Neo4jNode with properties: NodeID: 6 NodeData: [1×1 struct] NodeLabels: 'Scientist'
nodeinfo
is a Neo4jNode
object with these properties:
Node identifier
Node data
Node labels
Close the database connection.
close(neo4jconn)
Create Two Nodes with Labels
Create two nodes with labels in a Neo4j® database. Access data in the nodes.
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);
Check the Message
property of the Neo4j connection object neo4jconn
. The blank Message
property indicates a successful connection.
neo4jconn.Message
ans = []
Create two nodes that represent two people in the database by using the Neo4j database connection. Use the 'Labels'
name-value pair argument to specify the node labels. One node has the label Person
, and the other node has two labels, Person
and Employee
.
labels = {{'Person'},{'Person','Employee'}}; nodeinfo = createNode(neo4jconn,'Labels',labels)
nodeinfo=2×3 table
NodeLabels NodeData NodeObject
__________ ____________ ___________________________________
35 'Person' [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
36 {2×1 cell} [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
nodeinfo
is a table with two rows, one for each person. The table contains these variables:
Node label
Node data
Neo4jNode
object
Access the Neo4jNode
object for the first node.
data = nodeinfo.NodeObject(1)
data = Neo4jNode with properties: NodeID: 35 NodeData: [1×1 struct] NodeLabels: 'Person'
data
is a Neo4jNode
object with these properties:
Node identifier
Node data
Node label
Access the node labels of both nodes.
nodeinfo.NodeObject(1).NodeLabels
ans = 'Person'
nodeinfo.NodeObject(2).NodeLabels
ans = 2×1 cell array
{'Person' }
{'Employee'}
Close the database connection.
close(neo4jconn)
Create Two Nodes with Labels and Properties
Create two nodes with labels and properties in a Neo4j® database. Access the data in the nodes.
Assume that you have graph data stored in a Neo4j database that represents a social neighborhood. This database has seven nodes and eight relationships. Each node has only one unique property key name
with a value ranging from User1
through User7
. Each relationship has the type knows
.
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);
Check the Message
property of the Neo4j connection object neo4jconn
. The blank Message
property indicates a successful connection.
neo4jconn.Message
ans = []
Create a table with two rows that contain the names and job titles of two people (users).
props = table(["User8";"User9"],["Analyst";"Technician"], ... 'VariableNames',{'Name','Title'});
Create two nodes that represent these two people in the database by using the Neo4j database connection. Use the 'Labels'
name-value pair argument to specify the node labels Person
and Employee
. Then, use the 'Properties'
name-value pair argument to specify the node properties using the props
table.
labels = ["Person","Employee"]; nodeinfo = createNode(neo4jconn,'Labels',labels,'Properties',props)
nodeinfo=2×3 table
NodeLabels NodeData NodeObject
__________ ____________ ___________________________________
28 {2×1 cell} [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
21 {2×1 cell} [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
nodeinfo
is a table with two rows, one for each person. The table contains these variables:
Node label
Node data
Neo4jNode
object
Access the properties of the first node. This structure contains the properties of the node as fields and values.
nodeinfo.NodeData{1}
ans = struct with fields:
Title: 'Analyst'
Name: 'User8'
Access the Neo4jNode
object for the first node.
data = nodeinfo.NodeObject(1)
data = Neo4jNode with properties: NodeID: 28 NodeData: [1×1 struct] NodeLabels: {2×1 cell}
data
is a Neo4jNode
object with these properties:
Node identifier
Node data
Node label
Close the database connection.
close(neo4jconn)
Input Arguments
neo4jconn
— Neo4j database connection
Neo4jConnect
object
Neo4j database connection, specified as a Neo4jConnect
object created with the function neo4j
.
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example: node =
createNode(neo4jconn,'Labels','Person','Properties',table(["User8"],["Analyst"],'VariableNames',{'Name','Title'}))
creates a single node with the label Person
and two properties,
Name
and Title
, with their corresponding
values, User8
and Analyst
.
Labels
— Node labels
character vector | string scalar | cell array of character vectors | string array | cell array of cell arrays | cell array of string arrays
Node labels, specified as the comma-separated pair consisting of
'Labels'
and a character vector, string scalar,
cell array of character vectors, string array, cell array of cell
arrays, or cell array of string arrays. To specify one node label, use a
character vector or string scalar. For multiple node labels, use a cell
array of character vectors or a string array. To create multiple nodes
with different labels, use a cell array of cell arrays or a cell array
of string arrays.
Note
If you do not specify any labels, then the created node has no labels by default.
Example: 'Labels','Person'
Data Types: char
| string
| cell
Properties
— Node properties
structure | structure array | table | cell array of structures
Node properties, specified as the comma-separated pair consisting of
'Properties'
and a structure, structure array,
table, or cell array of structures.
When you specify a structure, the createNode
function converts each field and its corresponding value to a property
and its corresponding value in the database node. The function also sets
the NodeData
property of the Neo4jNode
object to this
structure.
When you specify a table that contains one row, the
createNode
function converts each variable and
its corresponding value to a property and its corresponding value in the
database node. The function also converts the variables and their
corresponding values to fields and their corresponding values in a
structure. The function sets this structure to the
NodeData
property of the
Neo4jNode
object.
To create multiple nodes, specify a structure array or table with multiple rows.
To create multiple nodes with different properties, specify a cell array of structures.
Note
If a property is missing its corresponding value, then the created node does not contain this property.
Data Types: struct
| table
| cell
Output Arguments
nodeinfo
— Node information
Neo4jNode
object | table
Node information in the Neo4j database, returned as a Neo4jNode
object for one node or as a table for multiple nodes.
For multiple nodes, the table contains these variables:
NodeLabels
— Cell array of character vectors that contains the node labels for each database nodeNodeData
— Cell array of structures that contains node information such as property keysNodeObject
—Neo4jNode
object for each database node
The row names of the table are Neo4j node identifiers of each database node.
Version History
Introduced in R2018a
Comando MATLAB
Hai fatto clic su un collegamento che corrisponde a questo comando MATLAB:
Esegui il comando inserendolo nella finestra di comando MATLAB. I browser web non supportano i comandi MATLAB.
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)