Query find().nodes()
can apply filters on nodes and return those that meet the requirement. This is very similar to table query in traditional database.
Syntax:
- Statement alias: supported (NODE)
- Prefix: OPTIOANL (returns
null
for any subquery that finds no result) - Optional parameters:
Parameter | Type | Specification | Description | Structure of Custom Alias |
---|---|---|---|---|
limit() |
Int | -1 or >=0 | Number of results to return for each subquery, -1 means to return all results | Not supported |
An alias nodes will be automatically defined by system when there is no manually defined alias at the end of the node query statement; in this case user cannot use nodes to define alias for other data in the subsequent UQL statement, otherwise error of duplicated name will be triggered.
Sample graph: (to be used for the following examples)
Run below UQLs one by one in an empty graphset to create graph data:create().node_schema("professor").node_schema("student")
create().node_property(@*, "age", int32).node_property(@*, "email", string)
insert().into(@professor).nodes([{_id:"P001",_uuid:1,age:53,email:"[email protected]"},{_id:"P002",_uuid:2,age:27,email:"[email protected]"}])
insert().into(@student).nodes([{_id:"S001",_uuid:3,age:27,email:"[email protected]"},{_id:"S002",_uuid:4,age:20,email:"[email protected]"},{_id:"S003",_uuid:5,age:25,email:"[email protected]"}])
No Filter
Example: Find any node, carry all properties
find().nodes() as n
return n{*}
|--------------- @professor --------------|
| _id | _uuid | age | email |
|-------|-------|-------|-----------------|
| P001 | 1 | 53 | [email protected] |
| P002 | 2 | 27 | [email protected] |
|---------------- @student ---------------|
| _id | _uuid | age | email |
|-------|-------|-------|-----------------|
| S001 | 3 | 27 | [email protected] |
| S002 | 4 | 20 | [email protected] |
| S003 | 5 | 25 | [email protected] |
Filter ID
Example: Find node with _id
S001, carry all properties
find().nodes({_id == "S001"}) as n
return n{*}
|---------------- @student ---------------|
| _id | _uuid | age | email |
|-------|-------|-------|-----------------|
| S001 | 3 | 27 | [email protected] |
Example: Find nodes with _uuid
1 or 3, carry all properties
find().nodes([1,3]) as n
return n{*}
|--------------- @professor --------------|
| _id | _uuid | age | email |
|-------|-------|-------|-----------------|
| P001 | 1 | 53 | [email protected] |
|---------------- @student ---------------|
| _id | _uuid | age | email |
|-------|-------|-------|-----------------|
| S001 | 3 | 27 | [email protected] |
Filter Schema
Example: Find nodes of @student, carry all properties
find().nodes({@student}) as n
return n{*}
|---------------- @student ---------------|
| _id | _uuid | age | email |
|-------|-------|-------|-----------------|
| S001 | 3 | 27 | [email protected] |
| S002 | 4 | 20 | [email protected] |
| S003 | 5 | 25 | [email protected] |
Filter Property
Example: Find nodes with age greater than 25, carry all properties
find().nodes({age > 25}) as n
return n{*}
|--------------- @professor --------------|
| _id | _uuid | age | email |
|-------|-------|-------|-----------------|
| P001 | 1 | 53 | [email protected] |
| P002 | 2 | 27 | [email protected] |
|---------------- @student ---------------|
| _id | _uuid | age | email |
|-------|-------|-------|-----------------|
| S001 | 3 | 27 | [email protected] |
Filter Schema & Property
Example: Find nodes of @student with age greater than 25, carry all properties
find().nodes({@student.age > 25}) as n
return n{*}
|---------------- @student ---------------|
| _id | _uuid | age | email |
|-------|-------|-------|-----------------|
| S001 | 3 | 27 | [email protected] |
limit()
Example: Find 3 nodes, carry all properties
find().nodes().limit(3) as n
return n{*}
|--------------- @professor --------------|
| _id | _uuid | age | email |
|-------|-------|-------|-----------------|
| P001 | 1 | 53 | [email protected] |
| P002 | 2 | 27 | [email protected] |
|---------------- @student ---------------|
| _id | _uuid | age | email |
|-------|-------|-------|-----------------|
| S001 | 3 | 27 | [email protected] |
Default Statement Alias
Example: Find 3 nodes, carry all properties
find().nodes().limit(3)
return nodes{*}
|--------------- @professor --------------|
| _id | _uuid | age | email |
|-------|-------|-------|-----------------|
| P001 | 1 | 53 | [email protected] |
| P002 | 2 | 27 | [email protected] |
|---------------- @student ---------------|
| _id | _uuid | age | email |
|-------|-------|-------|-----------------|
| S001 | 3 | 27 | [email protected] |
OPTIONAL
Example: Find nodes with age greater than 55, carry all properties; return null
if no result
optional find().nodes({age > 55}) as n
return n{*}
null
Analysis: This query will give no return if not using OPTIONAL.