语句 find().nodes()
可以对点进行过滤,并返回满足条件的点。类似于传统数据库中的表查询操作。
语法:
- 语句别名:支持,结构为 NODE
- 支持前缀 OPTIONAL,子查询无结果时返回
null
- 可选参数:
参数 | 类型 | 规范 | 描述 | 参数别名类型 |
---|---|---|---|---|
limit() |
int | -1 或 >=0 | 子查询返回结果的条数,-1 表示返回所有结果 | 不支持 |
未定义语句别名时系统将定义 nodes 为语句别名,此时不能在后面的语句中再次使用 nodes 为其它数据定义别名,否则会引发重名报错。
示例图集:(以下示例将在本图基础上运行)
在空图集中依次运行以下各行代码以创建该图数据: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:"test@yahoo.cn"},{_id:"P002",_uuid:2,age:27,email:"test@ultipa.com"}])
insert().into(@student).nodes([{_id:"S001",_uuid:3,age:27,email:"test@yeah.net"},{_id:"S002",_uuid:4,age:20,email:"test@w3.org"},{_id:"S003",_uuid:5,age:25,email:"test@gmail.com"}])
无过滤条件
示例:查询全部节点,携带全部属性值
find().nodes() as n
return n{*}
|--------------- @professor --------------|
| _id | _uuid | age | email |
|-------|-------|-------|-----------------|
| P001 | 1 | 53 | test@yahoo.cn |
| P002 | 2 | 27 | test@ultipa.com |
|---------------- @student ---------------|
| _id | _uuid | age | email |
|-------|-------|-------|-----------------|
| S001 | 3 | 27 | test@yeah.net |
| S002 | 4 | 20 | test@w3.org |
| S003 | 5 | 25 | test@gmail.com |
过滤 ID
示例:查询 _id
为 S001 的节点,携带全部属性值
find().nodes({_id == "S001"}) as n
return n{*}
|---------------- @student ---------------|
| _id | _uuid | age | email |
|-------|-------|-------|-----------------|
| S001 | 3 | 27 | test@yeah.net |
示例:查询 _uuid
为 1、3 的节点,携带全部属性值
find().nodes([1,3]) as n
return n{*}
|--------------- @professor --------------|
| _id | _uuid | age | email |
|-------|-------|-------|-----------------|
| P001 | 1 | 53 | test@yahoo.cn |
|---------------- @student ---------------|
| _id | _uuid | age | email |
|-------|-------|-------|-----------------|
| S001 | 3 | 27 | test@yeah.net |
过滤 Schema
示例:查询 @student 点,携带全部属性值
find().nodes({@student}) as n
return n{*}
|---------------- @student ---------------|
| _id | _uuid | age | email |
|-------|-------|-------|-----------------|
| S001 | 3 | 27 | test@yeah.net |
| S002 | 4 | 20 | test@w3.org |
| S003 | 5 | 25 | test@gmail.com |
过滤属性值
示例:查询 age 大于 25 的节点,携带全部属性值
find().nodes({age > 25}) as n
return n{*}
|--------------- @professor --------------|
| _id | _uuid | age | email |
|-------|-------|-------|-----------------|
| P001 | 1 | 53 | test@yahoo.cn |
| P002 | 2 | 27 | test@ultipa.com |
|---------------- @student ---------------|
| _id | _uuid | age | email |
|-------|-------|-------|-----------------|
| S001 | 3 | 27 | test@yeah.net |
过滤 Schema、属性值
示例:查询 age 大于 25 的 @student 点,携带全部属性值
find().nodes({@student.age > 25}) as n
return n{*}
|---------------- @student ---------------|
| _id | _uuid | age | email |
|-------|-------|-------|-----------------|
| S001 | 3 | 27 | test@yeah.net |
limit()
示例:查询 3 个节点,携带全部属性值
find().nodes().limit(3) as n
return n{*}
|--------------- @professor --------------|
| _id | _uuid | age | email |
|-------|-------|-------|-----------------|
| P001 | 1 | 53 | test@yahoo.cn |
| P002 | 2 | 27 | test@ultipa.com |
|---------------- @student ---------------|
| _id | _uuid | age | email |
|-------|-------|-------|-----------------|
| S001 | 3 | 27 | test@yeah.net |
使用默认的语句别名
示例:查询 3 个节点,携带全部属性值
find().nodes().limit(3)
return nodes{*}
|--------------- @professor --------------|
| _id | _uuid | age | email |
|-------|-------|-------|-----------------|
| P001 | 1 | 53 | test@yahoo.cn |
| P002 | 2 | 27 | test@ultipa.com |
|---------------- @student ---------------|
| _id | _uuid | age | email |
|-------|-------|-------|-----------------|
| S001 | 3 | 27 | test@yeah.net |
使用 OPTIONAL
示例:查询 age 大于 55 的节点,携带全部属性值;如无结果则返回 null
optional find().nodes({age > 55}) as n
return n{*}
null
分析:如不使用前缀 OPTIONAL,则无返回。