diff --git a/modules/ROOT/pages/clauses/filter.adoc b/modules/ROOT/pages/clauses/filter.adoc index fab35e07c..b51017673 100644 --- a/modules/ROOT/pages/clauses/filter.adoc +++ b/modules/ROOT/pages/clauses/filter.adoc @@ -93,6 +93,38 @@ RETURN p.name AS person, 3+|Rows: 2 |=== +[[filter-on-dynamic-labels-and-types]] +== Filter on dynamic labels and types + +To filter on a label or relationship type using a dynamically computed value, use `$()` where is any Cypher expression: + +.Parameters +[source, parameters] +---- +{ + "label": "Swedish" +} +---- + +.Filter on a dynamically computed node label +// tag::clauses_where_dynamic[] +[source, cypher] +---- +MATCH (n) +FILTER n:$($label) +RETURN labels(n) AS labels +---- +// end::clauses_where_dynamic[] + +.Result +[role="queryresult",options="header,footer",cols="1*)` where is any Cypher expression: + +.Parameters +[source, parameters] +---- +{ + "label": "Swedish" +} +---- + +.Filter on a dynamically computed node label +// tag::clauses_where_dynamic[] +[source, cypher] +---- +MATCH (n) +WHERE n:$($label) +RETURN labels(n) AS labels +---- +// end::clauses_where_dynamic[] + +.Result +[role="queryresult",options="header,footer",cols="1*() +WHERE n:$() +WITH n, r:$() AS hasType +RETURN n:$() +---- + +| Added the ability to dynamically reference node labels and relationship types in places where xref:patterns/reference.adoc#label-expressions[label expressions] are allowed. +|=== + + [[cypher-deprecations-additions-removals-2025.06]] == Neo4j 2025.06 diff --git a/modules/ROOT/pages/patterns/reference.adoc b/modules/ROOT/pages/patterns/reference.adoc index 2cf0114ff..a5009cfe8 100644 --- a/modules/ROOT/pages/patterns/reference.adoc +++ b/modules/ROOT/pages/patterns/reference.adoc @@ -314,6 +314,19 @@ The following matches relationships that have a type that is neither `A` nor `B` -[:!A&!B]-> ---- +[[dynamic-label-and-type-expressions]] +=== Dynamic label and type expressions + +Node labels and relationship types can be referenced dynamically in expressions, parameters, and variables within label expressions. + +.Syntax for creating nodes and relationships dynamically +[source, syntax] +---- +dynamicLabelExpression ::= ":$(" + valueExpression ")" +---- + +The `valueExpression` must evaluate to a `STRING NOT NULL | LIST NOT NULL` value. + [[property-key-value-expressions]] == Property key-value expressions