Overview
The clause find().nodes()
retrieves nodes from the graphset that meet specified conditions.
Syntax
Clause alias: NODE type; default alias is nodes
Method |
Param Type |
Param Spec |
Required |
Description | Alias |
---|---|---|---|---|---|
nodes() |
Filter | / | Yes | The conditions of nodes to be retrieved | N/A |
limit() |
Integer | ≥-1 | No | Number of results to return for each subquery, -1 signifies returning all |
N/A |
Examples
Example Graph
Run these UQLs row by row in an empty graphset to create this graph:
create().node_schema("professor").node_schema("student").edge_schema("mentor").edge_schema("assist")
create().node_property(@*, "age", int32).node_property(@*, "email", string).edge_property(@*, "year", int32)
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]"}])
insert().into(@mentor).edges([{_uuid:1, _from_uuid:2, _to_uuid:3, year:2020},{_uuid:2, _from_uuid:1, _to_uuid:3, year:2021},{_uuid:3, _from_uuid:1, _to_uuid:4, year:2021},{_uuid:4, _from_uuid:1, _to_uuid:5, year:2022}])
insert().into(@assist).edges([{_uuid:5, _from_uuid:3, _to_uuid:2, year:2020},{_uuid:6, _from_uuid:4, _to_uuid:1, year:2022}])
Find All Nodes
find().nodes() as n
return n{*}
Result:
_id | _uuid | Schema | age | email |
---|---|---|---|---|
P001 | 1 | professor | 53 | [email protected] |
P002 | 2 | professor | 27 | [email protected] |
_id | _uuid | Schema | age | email |
---|---|---|---|---|
S001 | 3 | student | 27 | [email protected] |
S002 | 4 | student | 20 | [email protected] |
S003 | 5 | student | 25 | [email protected] |
Find Nodes by ID
find().nodes({_id == "S001"}) as n
return n{*}
Result:
_id | _uuid | Schema | age | email |
---|---|---|---|---|
S001 | 3 | student | 27 | [email protected] |
find().nodes({_id in ["P001", "P002"]}) as n
return n{*}
Result:
_id | _uuid | Schema | age | email |
---|---|---|---|---|
P001 | 1 | professor | 53 | [email protected] |
P002 | 2 | professor | 27 | [email protected] |
Find Nodes by UUID
find().nodes(1) as n
return n{*}
The filter
{_uuid == 1}
can be simplified to1
.
Result:
_id | _uuid | Schema | age | email |
---|---|---|---|---|
P001 | 1 | professor | 53 | [email protected] |
find().nodes([1,3]) as n
return n{*}
The filter
{_uuid in [1,3]}
can be simplified to[1,3]
.
Result:
_id | _uuid | Schema | age | email |
---|---|---|---|---|
P001 | 1 | professor | 53 | [email protected] |
_id | _uuid | Schema | age | email |
---|---|---|---|---|
S001 | 3 | student | 27 | [email protected] |
Find Nodes by Schema
find().nodes({@student}) as n
return n{*}
Result:
_id | _uuid | Schema | age | email |
---|---|---|---|---|
S001 | 3 | student | 27 | [email protected] |
S002 | 4 | student | 20 | [email protected] |
S003 | 5 | student | 25 | [email protected] |
find().nodes({@student || @professor}) as n
return n{*}
Result:
_id | _uuid | Schema | age | email |
---|---|---|---|---|
P001 | 1 | professor | 53 | [email protected] |
P002 | 2 | professor | 27 | [email protected] |
_id | _uuid | Schema | age | email |
---|---|---|---|---|
S001 | 3 | student | 27 | [email protected] |
S002 | 4 | student | 20 | [email protected] |
S003 | 5 | student | 25 | [email protected] |
Find Nodes by Property
find().nodes({age > 30}) as n
return n{*}
Result:
_id | _uuid | Schema | age | email |
---|---|---|---|---|
P001 | 1 | professor | 53 | [email protected] |
Find Nodes by Schema and Property
find().nodes({@student.age > 25}) as n
return n{*}
Result:
_id | _uuid | Schema | age | email |
---|---|---|---|---|
S001 | 3 | student | 27 | [email protected] |
Use Default Clause Alias
find().nodes().limit(1)
return nodes{*}
Result:
_id | _uuid | Schema | age | email |
---|---|---|---|---|
P001 | 1 | professor | 53 | [email protected] |
Use limit()
find().nodes().limit(3) as n
return n{*}
Result:
_id | _uuid | Schema | age | email |
---|---|---|---|---|
P001 | 1 | professor | 53 | [email protected] |
P002 | 2 | professor | 27 | [email protected] |
_id | _uuid | Schema | age | email |
---|---|---|---|---|
S001 | 3 | student | 27 | [email protected] |
Use OPTIONAL
uncollect [53, 55, 57] as value
optional find().nodes({age == value}) as n
return n{*}
Result:
_id | _uuid | Schema | age | email |
---|---|---|---|---|
P001 | 1 | professor | 53 | [email protected] |
_id | _uuid | Schema |
---|---|---|
null | null | null |
null | null | null |
If the prefix OPTIONAL
is not used, null results will not be returned.