node

The node module provides a comprehensive toolkit for managing graph nodes, enabling creation, deletion, updating, merging, and more.

docs-source (opens in a new tab)

TraitValue
Module typeutil
ImplementationC++
Graph directiondirected/undirected
Edge weightsweighted/unweighted
Parallelismsequential

Procedures

relationship_types(node, types)

Returns a list of distinct relationship types of the given node contained within the given list of types. If the list of types is empty returns all distinct relationship types. Relationship types can also be directed:

  • <type - incoming relationship.
  • type> - outgoing relationship.
  • type - either way.

Input:

  • node: Node ➡ the given node.
  • types: List[string] (default = []) ➡ list of relationship types to filter by.

Output:

  • relationship_types: List[string] ➡ list of distinct relationship types contained within the given list of types.

Usage:

CREATE (ivan: Intern {name: 'Ivan'})
CREATE (idora: Intern {name: 'Idora'})
CREATE (matija: Intern {name: 'Matija'})
MERGE (ivan)-[:KNOWS]->(idora)
MERGE (matija)-[:HEARS]->(idora)
MERGE (matija)-[:SEES]->(ivan);
MATCH (intern:Intern) CALL node.relationship_types(intern, ["<KNOWS", "SEES>", "HEARS"]) yield relationship_types return intern.name as name, relationship_types;
+--------------------------------+
| name      relationship_types   |
+--------------------------------+
| Ivan      []                   |
+--------------------------------+
| Idora     ["HEARS", "KNOWS"]   |
+--------------------------------+
| Matija    ["SEES", "HEARS"]    |
+--------------------------------+

relationship_exists(node, pattern)

Checks if given node has a relationship of the pattern.

Input:

  • node: Node ➡ node for which relationship existance is to be verified.
  • pattern: List[string] (optional) ➡ list of relationship types for which it will be checked if at least one of them exists; if nothing is stated, procedure checks all types of relationships.

If < is added in front of the relationship type, only relationships coming into the node will be checked (e.g., "<KNOWS"), while if > is added at the end of the relationship type, only relationships coming from the node will be checked (e.g., "KNOWS>"). Furthermore, if relationship type is not relevant, it is possible to enter only < or > to check incoming or outgoing relationships.

Output:

  • exists: bool ➡ whether or not provided node has a relationship of specified type.

Usage:

MERGE (a:Person {name: "Phoebe"}) MERGE (b:Person {name: "Joey"}) CREATE (a)-[f:FRIENDS]->(b);
MATCH (a:Person {name: "Joey"}) CALL node.relationship_exists(a, ["<FRIENDS"]) 
YIELD exists RETURN exists;
+----------------------------+
| exists                     |
+----------------------------+
| True                       |
+----------------------------+

relationships_exist(node, relationships)

Checks if relationships in the input list exist at the given node. Results are returned as a map, represented as string-bool pair, where string represents the relationship, and bool represents if the relationship exists or not. Relationships can be directed, and the syntax for direction specification is provided below:

  • <type - incoming relationship.
  • type> - outgoing relationship.
  • type - both incoming and outgoing.
  • anything else results in an exception.

Input:

  • node: Node ➡ the input node.
  • relationships: List[string] ➡ list of relationships to be checked.

Output:

  • result: Map ➡ map of string-bool pairs, where string represents the relationship, and bool represents if the relationship exist or not. Example: {rel1: true, rel2>: false} means rel1 exists, and outgoing rel2 doesn't exist.

Usage:

CREATE (d:Dog)-[l:LOVES]->(h:Human)-[t:TAKES_CARE_OF]->(d);
MATCH (d:Dog) CALL node.relationships_exist(d, ["LOVES>", "TAKES_CARE_OF", "FOLLOWS", "<LOVES"]) YIELD result RETURN result;
+----------------------------------------------------------------------------+
| result                                                                     |
+----------------------------------------------------------------------------+
| {"<LOVES": false, "FOLLOWS": false, "LOVES>": true, "TAKES_CARE_OF": true} |                  
+----------------------------------------------------------------------------+
MATCH (h:Human) CALL node.relationships_exist(h, ["LOVES>", "TAKES_CARE_OF", "FOLLOWS", "<LOVES"]) YIELD result RETURN result;
+----------------------------------------------------------------------------+
| result                                                                     |
+----------------------------------------------------------------------------+
| {"<LOVES": true, "FOLLOWS": false, "LOVES>": false, "TAKES_CARE_OF": true} |                  
+----------------------------------------------------------------------------+