Search Neo4j database nodes by label or by property key and value
narrows the search for nodes with additional options specified by the
nodeinfo
= searchNode(neo4jconn
,nlabel
,Name,Value
)Name,Value
pair arguments.
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 = []
Search the database for nodes that have node label Person
using the Neo4j database connection neo4jconn
.
nlabel = 'Person';
nodeinfo = searchNode(neo4jconn,nlabel)
nodeinfo=7×3 table
NodeLabels NodeData NodeObject
__________ ____________ ___________________________________
0 'Person' [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
1 'Person' [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
2 'Person' [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
3 'Person' [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
4 'Person' [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
5 'Person' [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
9 'Person' [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
nodeinfo
is a table that contains information for each database node:
Each row name is a node identifier.
Variable NodeLabels
is the node label.
Variable NodeData
is the node information.
Variable NodeObject
is the Neo4jNode
object.
Access the node information for the first node in the table. The structure contains one property key and value.
node = nodeinfo.NodeData(1); node{1}
ans = struct with fields:
name: 'User1'
Access the node information using the row name as an index. The structure contains one property key and value.
nodeinfo.NodeData{'0'}
ans = struct with fields:
name: 'User1'
Find the node degree for the first database node in the table. Specify outgoing relationships. There are two outgoing relationships from the first node in the table with relationship type knows
.
degree = nodeDegree(nodeinfo.NodeObject(1),'out')
degree = struct with fields:
knows: 2
Close the database connection.
close(neo4jconn)
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 = []
Search the database for nodes that have node label Person
using the Neo4j database connection neo4jconn
. Filter the results further by the property key and value for a specific person named User2
. The nodeinfo
output argument is a Neo4jNode
object that contains node information.
nlabel = 'Person'; nodeinfo = searchNode(neo4jconn,nlabel,'PropertyKey','name', ... 'PropertyValue','User2')
nodeinfo = Neo4jNode with properties: NodeID: 2 NodeData: [1×1 struct] NodeLabels: 'Person'
Access the node information. The structure contains a property key and value for User2
.
nodeinfo.NodeData
ans = struct with fields:
name: 'User2'
Find the node degree of the outgoing relationships. There is one outgoing relationship type knows
for User2
.
degree = nodeDegree(nodeinfo,'out')
degree = struct with fields:
knows: 1
Close the database connection.
close(neo4jconn)
neo4jconn
— Neo4j database connectionNeo4jConnect
objectNeo4j database connection, specified as a Neo4jConnect
object created with the function neo4j
.
nlabel
— Neo4j database node labelNeo4j database node label, specified as a character vector or string scalar.
Data Types: char
| string
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
.
nodeinfo =
searchNode(neo4jconn,'Person','PropertyKey','name','PropertyValue','User2');
'PropertyKey'
— Property keyProperty key, specified as a comma-separated pair consisting of
'PropertyKey'
and a character vector or string
scalar. A property key must have a corresponding property value. To
specify the property value, use the name-value pair argument
'PropertyValue'
.
Example: 'PropertyKey','name'
Data Types: char
| string
'PropertyValue'
— Property valueProperty value, specified as a comma-separated pair consisting of
'PropertyValue'
and a character vector or string
scalar. A property value must have a corresponding property key. To
specify the property key, use the name-value pair argument
'PropertyKey'
.
Example: 'PropertyValue','User1'
Data Types: char
| string
nodeinfo
— Node informationNeo4jNode
object | tableNode 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 node
NodeData
— Cell array of structures that contains node
information such as property keys
NodeObject
— Neo4jNode
object for each
database node
The row names of the table are Neo4j node identifiers of each database node.
close
| neo4j
| nodeDegree
| nodeRelationTypes
| searchGraph
| searchNodeByID
| searchRelation
You have a modified version of this example. Do you want to open this example with your edits?