This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

createNode

Create nodes in Neo4j database

Syntax

nodeinfo = createNode(neo4jconn)
nodeinfo = createNode(neo4jconn,Name,Value)

Description

example

nodeinfo = createNode(neo4jconn) creates a single node without labels and properties by using a Neo4j® database connection.

example

nodeinfo = createNode(neo4jconn,Name,Value) creates a single node or multiple nodes by specifying additional options using one or more name-value pair arguments. For example, 'Labels','Person' creates a node with the Person node label.

Examples

collapse all

Create a single node in the 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 Neo4j database using the Neo4j database connection.

nodeinfo = createNode(neo4jconn)
nodeinfo = 

  Neo4jNode with properties:

        NodeID: 30
      NodeData: [1×1 struct]
    NodeLabels: []

nodeinfo is a Neo4jNode object with these properties:

  • Node identifier

  • Node data

  • Node labels

When you execute the createNode function without any arguments except the Neo4j database connection, the function creates a single node without labels and properties. To add labels and properties, use the updateNode function.

Create a single node with a node 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 in the Neo4j database with a node label using the Neo4j database connection. Use the 'Labels' name-value pair argument to specify the Person node label.

label = 'Person';
nodeinfo = createNode(neo4jconn,'Labels',label)
nodeinfo = 

  Neo4jNode with properties:

        NodeID: 31
      NodeData: [1×1 struct]
    NodeLabels: 'Person'

nodeinfo is a Neo4jNode object with these properties:

  • Node identifier

  • Node data

  • Node labels

Display the node label for this node.

nodeinfo.NodeLabels
ans =

    'Person'

Create two nodes with labels in the 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 Neo4j database by using the Neo4j database connection. Use the 'Labels' name-value pair argument to specify the node labels. One node has the Person node label and the other node has two node labels, Person and Employee.

labels = {{'Person'},{'Person','Employee'}};
nodeinfo = createNode(neo4jconn,'Labels',labels)
nodeinfo =

  2×3 table

          NodeLabels      NodeData                NodeObject          
          __________    ____________    ______________________________

    32    {1×1 cell}    [1×1 struct]    [1x1 database.neo4j.Neo4jNode]
    33    {2×1 cell}    [1×1 struct]    [1x1 database.neo4j.Neo4jNode]

nodeinfo is a table with two rows, one for each person. The table contains these variables:

  • Node labels

  • Node properties

  • Neo4jNode object

Access the Neo4jNode object for the first node.

data = nodeinfo.NodeObject(1)
data = 

  Neo4jNode with properties:

        NodeID: 32
      NodeData: [1×1 struct]
    NodeLabels: {'Person'}

data is a Neo4jNode object with these properties:

  • Node identifier

  • Node data

  • Node labels

Access the node labels of both nodes.

nodeinfo.NodeObject(1).NodeLabels
nodeinfo.NodeObject(2).NodeLabels
ans =

  1×1 cell array

    {'Person'}


ans =

  2×1 cell array

    {'Person'  }
    {'Employee'}

Create two nodes with labels and properties in the 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 values 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.

props = table(["User8";"User9"],["Analyst";"Technician"], ...
    'VariableNames',{'Name','Title'});

Create two nodes that represent these two people in the Neo4j 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          
          __________    ____________    ______________________________

    8     {2×1 cell}    [1×1 struct]    [1x1 database.neo4j.Neo4jNode]
    34    {2×1 cell}    [1×1 struct]    [1x1 database.neo4j.Neo4jNode]

nodeinfo is a table with two rows, one for each person. The table contains these variables:

  • Node labels

  • Node properties

  • 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: 'Technician'
     Name: 'User9'

Access the Neo4jNode object for the first node.

data = nodeinfo.NodeObject(1)
data = 

  Neo4jNode with properties:

        NodeID: 8
      NodeData: [1×1 struct]
    NodeLabels: {2×1 cell}

data is a Neo4jNode object with these properties:

  • Node identifier

  • Node data

  • Node labels

Input Arguments

collapse all

Neo4j database connection, specified as a Neo4jConnect object created with the function neo4j.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: node = createNode(neo4jconn,'Labels','Person','Properties',table(["User8"],["Analyst"],'VariableNames',{'Name','Title'})) creates a single node with the Person node label and two properties, Name and Title, and their corresponding values User8 and Analyst.

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 string array. To create multiple nodes with different node labels, use a cell array of cell arrays or 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

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, each field and its corresponding value convert to a property and its corresponding value in the database node. Also, the createNode function sets the NodeData property of the Neo4jNode object to this structure.

When you specify a table that contains one row, each variable and its corresponding value convert to a property and its corresponding value in the database node. The createNode function 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

collapse all

Node information in the Neo4j database, returned as a Neo4jNode object for one node or 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 node

  • NodeData — Cell array of structures that contains node information such as property keys

  • NodeObjectNeo4jNode object for each database node

The row names of the table are Neo4j node identifiers of each database node.

Introduced in R2018a