概述
find().nodes()
子句可以查询满足一定条件的点或全部点,与传统数据库中的表查询操作类似。
语法
- 子句别名:支持,数据类型为NODE,默认为nodes
- 支持前缀OPTIONAL:若无查询结果,子句返回null
- 命令:
find()
- 参数:
参数 | 类型 | 规范 | 必须携带 | 描述 |
参数别名 |
---|---|---|---|---|---|
nodes() |
filter | / | 是 | 点的过滤条件 | 不支持 |
limit() |
int | ≥-1 | 否 | 子句每次执行时返回的结果数量,-1 表示返回所有 |
不支持 |
没有自行定义
find().nodes()
子句别名时,系统使用默认的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 |
过滤UID
本例查询_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 |
限制查询数量
本例查询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,查询无结果时无返回值。