apoc.node.relationship.exists
语法 |
|
||
描述 |
根据给定`NODE`是否具有连接`RELATIONSHIP`(或者给定`NODE`是否具有给定类型和方向的连接`RELATIONSHIP`)返回`BOOLEAN`值。 |
||
参数 |
名称 |
类型 |
描述 |
|
|
要检查指定关系类型的节点。 |
|
|
|
要在给定节点上检查的关系类型。关系类型使用 APOC 的关系方向模式语法表示;`[<]RELATIONSHIP_TYPE1[>]|[<]RELATIONSHIP_TYPE2[>]|…`。默认值为空字符串。 |
|
返回 |
|
||
使用示例
本节示例基于以下样本图
MERGE (michael:Person {name: "Michael"})
WITH michael
CALL {
WITH michael
UNWIND range(0, 100) AS id
MERGE (p:Person {name: "Person" + id})
MERGE (michael)-[:KNOWS]-(p)
RETURN count(*) AS friends
}
CALL {
WITH michael
UNWIND range(0, 50) AS id
MERGE (p:Person {name: "Person" + id})
MERGE (michael)-[:FOLLOWS]-(p)
RETURN count(*) AS follows
}
RETURN friends, follows;
| friends | follows |
|---|---|
101 |
51 |
apoc.node.relationship.exists
MATCH (p1:Person {name: "Michael"})
RETURN apoc.node.relationship.exists(p1) AS output;
使用 Cypher 的 EXISTS {}
MATCH (p1:Person {name: "Michael"})
RETURN EXISTS {
(p1)--()
} AS output
| 输出 |
|---|
true |
apoc.node.relationship.exists
MATCH (p1:Person {name: "Person40"})
RETURN apoc.node.relationship.exists(p1, "FOLLOWS>") AS output;
使用 Cypher 的 EXISTS {}
MATCH (p1:Person {name: "Person40"})
RETURN EXISTS {
(p1)-[:FOLLOWS]->()
} AS output
| 输出 |
|---|
false |
apoc.node.relationship.exists
MATCH (p1:Person {name: "Person40"})
RETURN apoc.node.relationship.exists(p1, "<FOLLOWS") AS output;
使用 Cypher 的 EXISTS {}
MATCH (p1:Person {name: "Person40"})
RETURN EXISTS {
(p1)<-[:FOLLOWS]-()
} AS output
| 输出 |
|---|
true |