searchNode
Search Neo4j database nodes by label or by property key and value
Description
Examples
Search Nodes by Node Label
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 theNeo4jNode
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)
Search Nodes by Property Key and Value
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)
Input Arguments
neo4jconn
— Neo4j database connection
Neo4jConnect
object
Neo4j database connection, specified as a Neo4jConnect
object created with the function neo4j
.
nlabel
— Neo4j database node label
character vector | string scalar
Neo4j database node label, specified as a character vector or string scalar.
Data Types: char
| string
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: nodeinfo =
searchNode(neo4jconn,'Person','PropertyKey','name','PropertyValue','User2');
PropertyKey
— Property key
character vector | string scalar
Property 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 value
character vector | string scalar
Property 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
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 R2016b
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 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)