Cypher Cheat Sheet

Read Query

Read Query Structure

[USE]
[MATCH [WHERE]]
[OPTIONAL MATCH [WHERE]]
[WITH [ORDER BY] [SKIP] [LIMIT] [WHERE]]
RETURN [ORDER BY] [SKIP] [LIMIT]

Baseline for pattern search operations.

MATCH

MATCH (n)
RETURN n AS node

Match all nodes and return all nodes.

MATCH (n:Person)-[:OWNS]->(:Car)
RETURN n.name AS carOwners

Match all Person nodes with an OWNS relationship connected to a Car node, and return the name of the carOwners.

MATCH p=(:Person)-[:OWNS]->(:Car)
RETURN p AS path

Bind a path pattern to a path variable, and return the path pattern.

OPTIONAL MATCH

OPTIONAL MATCH (n:Person)-[r]->(m:Person {name: 'Alice'})
RETURN n, r, m

An OPTIONAL MATCH matches patterns against the graph database, just like a MATCH does. The difference is that if no matches are found, OPTIONAL MATCH will use a null for missing parts of the pattern.

MATCH (n:Person {name: 'Neo'})
OPTIONAL MATCH (n)-[r]->(m {name: 'Alice'})
RETURN n, r, m

MATCH should be used to find the the entities that must be present in the pattern. OPTIONAL MATCH should be used to find the entities that may not be present in the pattern.

WHERE

MATCH (n:Label)-->(m:Label)
WHERE n.property <> $value
RETURN n, m

WHERE can appear in a MATCH or OPTIONAL MATCH clause. It can also filter the results of a WITH clause.

MATCH (n)
WHERE n:A|B
RETURN n.name AS name

A label expression can be used as a predicate in the WHERE clause.

MATCH (n:Label)-[r]->(m:Label)
WHERE r:R1|R2
RETURN r.name AS name

A relationship type expression can be used as a predicate in the WHERE clause.

WITH 30 AS minAge
MATCH (a:Person WHERE a.name = 'Andy')-[:KNOWS]->(b:Person WHERE b.age > minAge)
RETURN b.name

WHERE can appear inside a MATCH clause.

MATCH (a:Person {name: 'Andy'})
RETURN [(a)-->(b WHERE b:Person) | b.name] AS friends

WHERE can appear inside a pattern comprehension statement.

WITH 2000 AS minYear
MATCH (a:Person)-[r:KNOWS WHERE r.since < minYear]->(b:Person)
RETURN r.since

A relationship type expression can be used as a predicate in a WHERE clause.

WITH 2000 AS minYear
MATCH (a:Person {name: 'Andy'})
RETURN [(a)-[r:KNOWS WHERE r.since < minYear]->(b:Person) | r.since] AS years

Relationship pattern predicates can be used inside pattern comprehension.

RETURN

MATCH (n:Label)-[r]->(m:Label)
RETURN *

Return the value of all variables.

MATCH (n:Label)-[r]->(m:Label)
RETURN n AS node, r AS rel

Use alias for result column name.

MATCH (n:Person)-[r:KNOWS]-(m:Person)
RETURN DISTINCT n AS node

Return unique rows.

MATCH (n:Label)-[r]->(m:Label)
RETURN n AS node, r AS rel
ORDER BY n.name

Sort the result. The default order is ASCENDING.

MATCH (n:Label)-[r]->(m:Label)
RETURN n AS node, r AS rel
ORDER BY n.name DESC

Sort the result in DESCENDING order.

MATCH (n:Label)-[r]->(m:Label)
RETURN n AS node, r AS rel
SKIP 10

Skip the 10 first rows, for the result set.

MATCH (n:Label)-[r]->(m:Label)
RETURN n AS node, r AS rel
LIMIT 10

Limit the number of rows to a maximum of 10, for the result set.

MATCH (n:Label)-[r]->(m:Label)
RETURN count(*) AS nbr

The number of matching rows. See aggregating functions for more.

MATCH (n)
RETURN n:A&B

A label expression can be used in the WITH or RETURN statement.

MATCH (n:Label)-[r]->(m:Label)
RETURN r:R1|R2 AS result

A relationship type expression can be used as a predicate in the WITH or RETURN statement.

WITH

MATCH (user)-[:FRIEND]-(friend)
WHERE user.name = $name
WITH user, count(friend) AS friends
WHERE friends > 10
RETURN user

The WITH syntax is similar to RETURN. It separates query parts explicitly, allowing users to declare which variables to carry over to the next part of the query.

MATCH (user)-[:FRIEND]-(friend)
WITH user, count(friend) AS friends
ORDER BY friends DESC
SKIP 1
LIMIT 3
WHERE friends > 10
RETURN user

The WITH clause can use:

  • ORDER BY

  • SKIP

  • LIMIT

  • WHERE

UNION

MATCH (a:Person)-[:KNOWS]->(b:Person)
RETURN b.name AS name
UNION
MATCH (a:Person)-[:LOVES]->(b:Person)
RETURN b.name AS name

Return the distinct union of all query results. Result column types and names have to match.

MATCH (a:Person)-[:KNOWS]->(b:Person)
RETURN b.name AS name
UNION ALL
MATCH (a:Person)-[:LOVES]->(b:Person)
RETURN b.name AS name

Return the union of all query results, including duplicated rows.

Write query

Write-Only Query Structure

[USE]
[CREATE]
[MERGE [ON CREATE ...] [ON MATCH ...]]
[WITH [ORDER BY] [SKIP] [LIMIT] [WHERE]]
[SET]
[DELETE]
[REMOVE]
[RETURN [ORDER BY] [SKIP] [LIMIT]]

Baseline for write operations.

Read-Write Query Structure

[USE]
[MATCH [WHERE]]
[OPTIONAL MATCH [WHERE]]
[WITH [ORDER BY] [SKIP] [LIMIT] [WHERE]]
[CREATE]
[MERGE [ON CREATE ...] [ON MATCH ...]]
[WITH [ORDER BY] [SKIP] [LIMIT] [WHERE]]
[SET]
[DELETE]
[REMOVE]
[RETURN [ORDER BY] [SKIP] [LIMIT]]

Baseline for pattern search and write operations.

CREATE

CREATE (n:Label {name: $value})

Create a node with the given label and properties.

CREATE (n:Label $map)

Create a node with the given label and properties.

CREATE (n:Label)-[r:TYPE]->(m:Label)

Create a relationship with the given relationship type and direction; bind a variable r to it.

CREATE (n:Label)-[:TYPE {name: $value}]->(m:Label)

Create a relationship with the given type, direction, and properties.

SET

SET e.property1 = $value1

Update or create a property.

SET
  e.property1 = $value1,
  e.property2 = $value2

Update or create several properties.

MATCH (n)
SET n[$key] = value

Dynamically set or update node properties.

MATCH (n)
SET n:$($label)

Dynamically set node labels.

SET e = $map

Set all properties. This will remove any existing properties.

SET e = {}

Using the empty map ({}), removes any existing properties.

SET e += $map

Add and update properties, while keeping existing ones.

MATCH (n:Label)
WHERE n.id = 123
SET n:Person

Add a label to a node. This example adds the label Person to a node.

MERGE

MERGE (n:Label {name: $value})
ON CREATE SET n.created = timestamp()
ON MATCH SET
  n.counter = coalesce(n.counter, 0) + 1,
  n.accessTime = timestamp()

Match a pattern or create it if it does not exist. Use ON CREATE and ON MATCH for conditional updates.

MATCH
  (a:Person {name: $value1}),
  (b:Person {name: $value2})
MERGE (a)-[r:LOVES]->(b)

MERGE finds or creates a relationship between the nodes.

MATCH (a:Person {name: $value1})

MERGE finds or creates paths attached to the node.

DELETE

MATCH (n:Label)-[r]->(m:Label)
WHERE r.id = 123
DELETE r

Delete a relationship.

MATCH ()-[r]->()
DELETE r

Delete all relationships.

MATCH (n:Label)
WHERE n.id = 123
DETACH DELETE n

Delete a node and all relationships connected to it.

MATCH (n:Label)-[r]-()
WHERE r.id = 123 AND n.id = 'abc'
DELETE n, r

Delete a node and a relationship. An error will be thrown if the given node is attached to more than one relationship.

MATCH (n1:Label)-[r {id: 123}]->(n2:Label)
CALL (n1) {
  MATCH (n1)-[r1]-()
  RETURN count(r1) AS rels1
}
CALL (n2) {
  MATCH (n2)-[r2]-()
  RETURN count(r2) AS rels2
}
DELETE r
RETURN
  n1.name AS node1, rels1 - 1 AS relationships1,
  n2.name AS node2, rels2 - 1 AS relationships2

Delete a relationship and return the number of relationships for each node after the deletion. This example uses a variable scope clause (introduced in Neo4j 5.23) to import variables into the CALL subquery. If you are using an older version of Neo4j, use an importing WITH clause instead.

MATCH (n)
DETACH DELETE n

Delete all nodes and relationships from the database.

REMOVE

MATCH (n:Label)
WHERE n.id = 123
REMOVE n:Label

Remove a label from a node.

MATCH (n {name: 'Peter'})
REMOVE n:$($label)
RETURN n.name

Dynamically remove node labels.

MATCH (n:Label)
WHERE n.id = 123
REMOVE n.alias

Remove a property from a node.

MATCH (n)
REMOVE n[$key]

Dynamically remove properties from nodes.

MATCH (n:Label)
WHERE n.id = 123
SET n = {} # REMOVE ALL properties

REMOVE cannot be used to remove all existing properties from a node or relationship. All existing properties can be removed from a node or relationship by using the SET clause with the property replacement operator (=) and an empty map ({}) as the right operand.

Patterns

Node patterns

(n)

Bind matched nodes to the variable n.

(n:Person)

Match nodes with the label Person.

(n:Person&Employee)

Node with both a Person label and an Employee label.

(n:Person|Company)

Node with either a Person label or a Company label (or both).

(n:!Person)

Node that does not have a Person label.

(n:%)

Node with at least one label.

(n:(!Person&!Employee)|Company)

Node with either no Person label and no Employee label, or with a Company label.

(n:Person {name: 'Alice'})

Match nodes with property name equal to 'Alice'.

(n:Person WHERE n.name STARTS WITH 'Al')

Node pattern with a WHERE predicate.

Relationship patterns

(n:Person)--(m:Person)

Relationship without a specified direction.

(n:Person)-->(m:Person)

Relationship with a specified direction.

(n:Person)-[r]->(m:Person)

Relationship with a declared relationship variable r.

(n:Person)-[r:KNOWS]->(m:Person)

Relationship of type KNOWS.

(n:Person)-[r:KNOWS|LIKES]->(m:Person)

Relationship of type KNOWS or LIKES.

(n:Person)-[r:!FRIEND_OF]->(m:Person)

Relationship of type that is not FRIEND_OF.

(n:Person)-[r:(!FRIEND_OF&!LIKES)|KNOWS]->(m:Person)

Relationship of type that is either not FRIEND_OF and not LIKES, or is KNOWS.

(n:Person)-[r:KNOWS {since: 1999}]->(m:Person)

Relationship with property since equal to 1999

(n:Person)-[r:KNOWS WHERE r.metIn STARTS WITH 'Sto']->(m:Person)

Relationship with property metIn that starts with 'Sto'.

Path patterns

(n:Person)

Path patterns must have at least one node pattern.

(n:Person)-[r:KNOWS]->(m:Person)

Path patterns must begin and end with a node pattern.

(n:Person {name: 'Alice'})-[r:KNOWS]->(m:Person)<-[r2:OWNS]-(c:Car {type: 'Volvo'})

Path patterns must alternate between nodes and relationships.

Equijoins

(n:Person {name: 'Alice'})-[:KNOWS]->(:Person)<-[:KNOWS]-(:Person)-[:KNOWS]-(n)

An equijoin is an operation on paths that requires more than one of the nodes or relationships of the paths to be the same. The equality between the nodes or relationships is specified by declaring a node variable or relationship variable more than once. An equijoin on nodes allows cycles to be specified in a path pattern. Due to relationship uniqueness, an equijoin on relationships yields no solutions.

Quantified path patterns

((m:Person)-[:KNOWS]->(n:Person) WHERE m.born < n.born){1,5}

Paths of between 1 and 5 hops of a Person who knows another Person younger than them.

(n:Person {name: "Alice"})-[:KNOWS]-{1,3}(m:Person)

Paths of between 1 and 3 hops of relationship of type KNOWS from Person with name Alice to another Person.

(n:Person {name: "Christina Ricci"}) (()-[:ACTED_IN]->(:Movie)<-[:ACTED_IN]-(:Person)){1,3} (m:Person)

Paths that connect Christina Ricci to a Person, traversing between 1 and 3 node pairs each consisting of two Person nodes with an ACTED_IN relationship to the same Movie.

(n:Person)-[:KNOWS]-{,4}(m:Person)-[:ACTED_IN]->(:Movie)<-[:ACTED_IN]-(:Person {name: "Christina Ricci"})

Paths from a Person within 4 hops of relationship of type KNOWS to a Person who ACTED_IN the same Movie as Christina Ricci.

Graph patterns

(n:Person {name: 'ALICE'})-[r:KNOWS]->(m:Person {name: 'Bob'})<--(o), (m)<-[:FRIEND_OF]-(p)

Multiple path patterns can be combined in a comma-separated list to form a graph pattern. In a graph pattern, each path pattern is matched separately, and where node variables are repeated in the separate path patterns, the solutions are reduced via equijoins.

Shortest paths

MATCH p = SHORTEST 1 (wos:Station)-[:LINK]-+(bmv:Station)
WHERE wos.name = "Worcester Shrub Hill" AND bmv.name = "Bromsgrove"
RETURN length(p) AS result

SHORTEST k finds the shortest path(s) (by number of hops) between nodes, where k is the number of paths to match.

MATCH p = ALL SHORTEST (wos:Station)-[:LINK]-+(bmv:Station)
WHERE wos.name = "Worcester Shrub Hill" AND bmv.name = "Bromsgrove"
RETURN [n in nodes(p) | n.name] AS stops

Find all shortest paths between two nodes.

MATCH p = SHORTEST 2 GROUPS (wos:Station)-[:LINK]-+(bmv:Station)
WHERE wos.name = "Worcester Shrub Hill" AND bmv.name = "Bromsgrove"
RETURN [n in nodes(p) | n.name] AS stops, length(p) AS pathLength

SHORTEST k GROUPS returns all paths that are tied for first, second, and so on, up to the kth shortest length. This example finds all paths with the first and second shortest lengths between two nodes.

MATCH p = ANY (:Station {name: 'Pershore'})-[l:LINK WHERE l.distance < 10]-+(b:Station {name: 'Bromsgrove'})
RETURN [r IN relationships(p) | r.distance] AS distances

The ANY keyword can be used to test the reachability of nodes from a given node(s). It returns the same as SHORTEST 1, but by using the ANY keyword the intent of the query is clearer.

Variable-length relationships

(n:Label)-[*0..]->(m:Label)

Variable-length path of between 0 or more hops between two nodes.

(n:Label)-[*3]->(m:Label)

Variable-length path of exactly 3 hops between two nodes.

(n:Label)-[*..3]->(m:Label)

Variable-length path of between 1 and 3 hops between two nodes.

(n:Label)-[*1..5]->(m:Label)

Variable-length path of between 1 and 5 hops between two nodes.

(n:Label)-[*]->(m:Label)

Variable-length path of one or more relationships (see the section on Performance for more information).

Clauses

CALL procedure

CALL db.labels() YIELD label

Standalone call to the procedure db.labels to list all labels used in the database. Note that required procedure arguments are given explicitly in brackets after the procedure name.

MATCH (n)
OPTIONAL CALL apoc.neighbors.tohop(n, "KNOWS>", 1)
YIELD node
RETURN n.name AS name, collect(node.name) AS connections

Optionally CALL a procedure. Similar to OPTIONAL MATCH, any empty rows produced by the OPTIONAL CALL will return null and not affect the remainder of the procedure evaluation.

CALL db.labels() YIELD *

Standalone calls may use YIELD * to return all columns.

CALL java.stored.procedureWithArgs

Standalone calls may omit YIELD and also provide arguments implicitly via statement parameters, e.g. a standalone call requiring one argument input may be run by passing the parameter map {input: 'foo'}.

CALL db.labels() YIELD label
RETURN count(label) AS db_labels

Calls the built-in procedure db.labels inside a larger query to count all labels used in the database. Calls inside a larger query always requires passing arguments and naming results explicitly with YIELD.

FOREACH

WITH ['Alice', 'Neo'] AS names
FOREACH ( value IN names | CREATE (:Person {name: value}) )

Run a mutating operation for each element in a list.

FOREACH ( r IN relationships(path) | SET r.marked = true )

Run a mutating operation for each relationship in a path.

LIMIT

MATCH (n)
RETURN n.name
ORDER BY n.name
LIMIT 3

LIMIT constrains the number of returned rows. It can be used in conjunction with ORDER BY and SKIP.

MATCH (n)
LIMIT 2
RETURN collect(n.name) AS names

LIMIT can be used as a standalone clause.

LOAD CSV

LOAD CSV FROM
'https://neo4j.com/docs/cypher-cheat-sheet/5/csv/artists.csv'
AS line
CREATE (:Artist {name: line[1], year: toInteger(line[2])})

Load data from a CSV file and create nodes.

LOAD CSV WITH HEADERS FROM
'https://neo4j.com/docs/cypher-cheat-sheet/5/csv/artists-with-headers.csv'
AS line
CREATE (:Artist {name: line.Name, year: toInteger(line.Year)})

Load CSV data which has headers.

LOAD CSV WITH HEADERS FROM
'https://neo4j.com/docs/cypher-cheat-sheet/5/csv/artists-with-headers.csv'
AS line
CALL (line) {
  CREATE (:Artist {name: line.Name, year: toInteger(line.Year)})
} IN TRANSACTIONS OF 500 ROWS

Subqueries can be made to execute in separate, inner transactions, producing intermediate commits. This example uses a variable scope clause (introduced in Neo4j 5.23) to import variables into the CALL subquery. If you are using an older version of Neo4j, use an importing WITH clause instead.

To instruct Neo4j Browser to submit the query as an implicit (auto-commit) transaction, prepend the query with :auto.

LOAD CSV FROM
'https://neo4j.com/docs/cypher-cheat-sheet/5/csv/artists-fieldterminator.csv'
AS line FIELDTERMINATOR ';'
CREATE (:Artist {name: line[1], year: toInteger(line[2])})

Use a different field terminator, not the default which is a comma (with no whitespace around it).

file()

The file() function returns a string (the absolute path of the file that LOAD CSV is processing). Returns null if called outside of LOAD CSV context.

linenumber()

The linenumber function returns an integer (the line number that LOAD CSV is currently processing). Returns null if called outside of LOAD CSV context.

ORDER BY

MATCH (n)
ORDER BY n.name DESC
SKIP 1
LIMIT 1
RETURN n.name AS name

ORDER BY specifies how the output of a clause should be sorted. It can be used as a sub-clause following RETURN or WITH or in in conjunction with ORDER BY and SKIP.

Unless ORDER BY is used, Neo4j does not guarantee the row order of a query result.

MATCH (n)
ORDER BY n.name
RETURN collect(n.name) AS names

ORDER BY can be used as a standalone clause.

SHOW FUNCTIONS

SHOW FUNCTIONS

List all available functions, returns only the default outputs (name, category, and description).

SHOW BUILT IN FUNCTIONS YIELD *

List built-in functions, can also be filtered on ALL or USER-DEFINED .

SHOW FUNCTIONS EXECUTABLE BY CURRENT USER YIELD *

Filter the available functions for the current user.

SHOW FUNCTIONS EXECUTABLE BY user_name

Filter the available functions for the specified user.

SHOW PROCEDURES

SHOW PROCEDURES

List all available procedures, returns only the default outputs (name, description, mode, and worksOnSystem).

SHOW PROCEDURES YIELD *

List all available procedures.

SHOW PROCEDURES EXECUTABLE YIELD name

List all procedures that can be executed by the current user and return only the name of the procedures.

SHOW SETTINGS

SHOW SETTINGS

List configuration settings (within the instance), returns only the default outputs (name, value, isDynamic, defaultValue, and description).

SHOW SETTINGS YIELD *

List configuration settings (within the instance).

SHOW SETTINGS 'server.bolt.advertised_address', 'server.bolt.listen_address' YIELD *

List the configuration settings (within the instance) named server.bolt.advertised_address and server.bolt.listen_address. As long as the setting names evaluate to a string or a list of strings at runtime, they can be any expression.

SHOW TRANSACTIONS

SHOW TRANSACTIONS

List running transactions (within the instance), returns only the default outputs (database, transactionId, currentQueryId, connectionId, clientAddress, username, currentQuery, startTime, status, and elapsedTime).

SHOW TRANSACTIONS YIELD *

List running transactions (within the instance).

SHOW TRANSACTIONS 'transaction_id' YIELD *

List the running transaction (within the instance), with a specific transaction_id. As long as the transaction IDs evaluate to a string or a list of strings at runtime, they can be any expression.

SKIP

MATCH (n)
ORDER BY n.name
SKIP 2
LIMIT 2
RETURN collect(n.name) AS names

SKIP defines from which row to start including the rows in the output. It can be used in conjunction with LIMIT and ORDER BY.

MATCH (n)
SKIP 2
RETURN collect(n.name) AS names

SKIP can be used as a standalone clause.

MATCH (n)
RETURN n.name
ORDER BY n.name
OFFSET 3

OFFSET can be used as a synonym to SKIP.

TERMINATE TRANSACTIONS

TERMINATE TRANSACTIONS 'transaction_id'

Terminate a specific transaction, returns the outputs: transactionId, username, message.

TERMINATE TRANSACTIONS $value
  YIELD transactionId, message
  RETURN transactionId, message

Terminal transactions allow for YIELD clauses. As long as the transaction IDs evaluate to a string or a list of strings at runtime, they can be any expression.

 SHOW TRANSACTIONS
  YIELD transactionId AS txId, username
  WHERE username = 'user_name'
TERMINATE TRANSACTIONS txId
  YIELD message
  WHERE NOT message = 'Transaction terminated.'
  RETURN txId

List all transactions by the specified user and terminate them. Return the transaction IDs of the transactions that failed to terminate successfully.

UNWIND

UNWIND [1, 2, 3] AS ix
RETURN ix + 1 AS item

The UNWIND clause expands a list into a sequence of rows.

Three rows are returned.

WITH [[1, 2], [3, 4], 5] AS nested
UNWIND nested AS ix
UNWIND ix AS iy
RETURN iy AS number

Multiple UNWIND clauses can be chained to unwind nested list elements.

Five rows are returned.

UNWIND $list_of_maps AS properties
CREATE (n:Label)
SET n = properties

Create a node for each map in the list and set the given properties.

UNWIND $names AS name
MATCH (n:Label {name: $value})
RETURN avg(n.age) AS average

With UNWIND, any list can be transformed back into individual rows. The example matches all names from a list of names.

USE

USE myDatabase

Select myDatabase to execute query, or query part, against.

USE neo4j
MATCH (n:Person)-[:KNOWS]->(m:Person)
WHERE n.name = 'Alice'

MATCH query executed against neo4j database.

Subqueries

CALL

UNWIND [0, 1, 2] AS x
CALL () {
  RETURN 'hello' AS innerReturn
}
RETURN innerReturn

A CALL subquery is executed once for each row. In this example, the CALL subquery executes three times.

MATCH (t:Team)
CALL (t) {
  MATCH (p:Player)-[:PLAYS_FOR]->(t)
  RETURN collect(p) as players
}
RETURN t AS team, players

Variables are imported into a CALL subquery using a variable scope clause, CALL (<variable>), or an importing WITH clause (deprecated). In this example, the subquery will process each Team at a time and collect a list of all Player nodes.

MATCH (t:Team)
OPTIONAL CALL (t) {
  MATCH (p:Player)-[:PLAYS_FOR]->(t)
  RETURN collect(p) as players
}
RETURN t AS team, players

Optionally CALL a subquery. Similar to OPTIONAL MATCH, any empty rows produced by the OPTIONAL CALL will return null and not affect the remainder of the subquery evaluation.

CALL () {
  MATCH (p:Player)
  RETURN p
  ORDER BY p.age ASC
  LIMIT 1
UNION
  MATCH (p:Player)
  RETURN p
  ORDER BY p.age DESC
  LIMIT 1
}
RETURN p.name AS name, p.age AS age

CALL subqueries can be used to further process the results of a UNION query. This example finds the youngest and the oldest Player in the graph.

CALL subqueries in transactions

LOAD CSV WITH HEADERS FROM 'https://data.neo4j.com/importing-cypher/books.csv' AS row
CALL (row) {
  MERGE (b:Book {id: row.id, title: row.title})
  MERGE (a:Author {name: row.author});
} IN TRANSACTIONS

CALL subqueries can execute in separate, inner transactions, producing intermediate commits.

LOAD CSV FROM 'https://data.neo4j.com/bands/artists.csv' AS line
CALL (line) {
  MERGE (:Person {name: line[1], age: toInteger(line[2])})
} IN TRANSACTIONS OF 2 ROWS

Specify the number of rows processed in each transaction.

UNWIND [1, 0, 2, 4] AS i
CALL (i) {
  CREATE (n:Person {num: 100/i})
  RETURN n
} IN TRANSACTIONS OF 1 ROW ON ERROR CONTINUE
RETURN n.num

There are three different option flags to control the behavior in case of an error occurring in any of the inner transactions:

  • ON ERROR CONTINUE - ignores a recoverable error and continues the execution of subsequent inner transactions. The outer transaction succeeds.

  • ON ERROR BREAK - ignores a recoverable error and stops the execution of subsequent inner transactions. The outer transaction succeeds.

  • ON ERROR FAIL - acknowledges a recoverable error and stops the execution of subsequent inner transactions. The outer transaction fails.

LOAD CSV WITH HEADERS FROM 'https://data.neo4j.com/importing-cypher/persons.csv' AS row
CALL (row) {
  MERGE (p:Person {tmdbId: row.person_tmdbId})
  SET p.name = row.name, p.born = row.born
} IN 3 CONCURRENT TRANSACTIONS OF 10 ROWS
RETURN count(*) AS personNodes

CALL subqueries can execute batches in parallel by appending IN [n] CONCURRENT TRANSACTIONS, where n is an optional concurrency value used to set the maximum number of transactions that can be executed in parallel.

COUNT, COLLECT, and EXISTS

MATCH (person:Person)
WHERE COUNT { (person)-[:HAS_DOG]->(:Dog) } > 1
RETURN person.name AS name

A COUNT subquery counts the number of rows returned by the subquery. Unlike CALL subqueries, variables introduced by the outer scope can be used in EXISTS, COLLECT, and COUNT subqueries.

MATCH (person:Person)
WHERE EXISTS {
  MATCH (person)-[:HAS_DOG]->(dog:Dog)
  WHERE person.name = dog.name
}
RETURN person.name AS name

An EXISTS subquery determines if a specified pattern exists at least once in the graph. A WHERE clause can be used inside COLLECT, COUNT, and EXISTS patterns.

MATCH (person:Person) WHERE person.name = "Peter"
SET person.dogNames = COLLECT { MATCH (person)-[:HAS_DOG]->(d:Dog) RETURN d.name }
RETURN person.dogNames as dogNames

A COLLECT subquery creates a list with the rows returned by the subquery. COLLECT, COUNT, and EXISTS subqueries can be used inside other clauses.

General

Operators

DISTINCT, ., []

General

+, -, *, /, %, ^

Mathematical

=, <>, <, >, <=, >=, IS NULL, IS NOT NULL

Comparison

AND, OR, XOR, NOT

Boolean

+

String

+, IN, [x], [x .. y]

List

=~

Regular expression

STARTS WITH, ENDS WITH, CONTAINS

String matching

null

null is used to represent missing/undefined values.

null is not equal to null. Not knowing two values does not imply that they are the same value. So the expression null = null yields null and not true. To check if an expression is null, use IS NULL.

Arithmetic expressions, comparisons and function calls (except coalesce) will return null if any argument is null.

An attempt to access a missing element in a list or a property that does not exist yields null.

In OPTIONAL MATCH clauses, nulls will be used for missing parts of the pattern.

Labels

CREATE (n:Person {name: $value})

Create a node with label and property.

MERGE (n:Person {name: $value})

Matches or creates unique node(s) with the label and property.

MATCH (n:Person)
RETURN n AS person

Matches nodes labeled Person .

MATCH (n)
WHERE (n:Person)

Checks the existence of the label Person on the node.

MATCH (n:Person)
WHERE n.name = $value

Matches nodes labeled Person with the given property name.

MATCH (n:Person {id: 123})
SET n:Spouse:Parent:Employee

Add label(s) to a node.

MATCH (n {id: 123})
RETURN labels(n) AS labels

The labels function returns the labels for the node.

MATCH (n {id: 123})
REMOVE n:Person

Remove the label :Person from the node.

Properties

MATCH (n {name: 'Alice'})
SET n += {
  a: 1,
  b: 'example',
  c: true,
  d: date('2022-05-04'),
  e: point({x: 2, y: 3}),
  f: [1, 2, 3],
  g: ['abc', 'example'],
  h: [true, false, false],
  i: [date('2022-05-04'), date()],
  j: [point({x: 2, y: 3}), point({x: 5, y: 5})],
  k: null
}

Neo4j only supports a subset of Cypher types for storage as singleton or array properties. Properties can be lists of numbers, strings, booleans, temporal, or spatial.

{a: 123, b: 'example'}

A map is not allowed as a property.

[{a: 1, b: 2}, {c: 3, d: 4}]

A list of maps are not allowed as a property.

[[1,2,3], [4,5,6]]

Collections containing collections cannot be stored in properties.

[1, 2, null]

Collections containing null values cannot be stored in properties.

Lists

RETURN ['a', 'b', 'c'] AS x

Literal lists are declared in square brackets.

WITH ['Alice', 'Neo', 'Cypher'] AS names
RETURN names

Literal lists are declared in square brackets.

RETURN size($my_list) AS len

Lists can be passed in as parameters.

RETURN $my_list[0] AS value

Lists can be passed in as parameters.

RETURN range($firstNum, $lastNum, $step) AS list

range() creates a list of numbers (step is optional), other functions returning lists are: labels(), nodes(), and relationships().

MATCH p = (a)-[:KNOWS*]->()
RETURN relationships(p) AS r

The list of relationships comprising a variable length path can be returned using named paths and relationships().

RETURN list[$idx] AS value

List elements can be accessed with idx subscripts in square brackets. Invalid indexes return null.

RETURN list[$startIdx..$endIdx] AS slice

Slices can be retrieved with intervals from start_idx to end_idx, each of which can be omitted or negative. Out of range elements are ignored.

MATCH (a:Person)
RETURN [(a:Person)-->(b:Person) WHERE b.name = 'Alice' | b.age] AS list

Pattern comprehensions may be used to do a custom projection from a match directly into a list.

MATCH (n:Person)
RETURN n {.name, .age}

Map projections may be easily constructed from nodes, relationships and other map values.

Maps

RETURN {name: 'Alice', age: 20, address: {city: 'London', residential: true}} AS alice

Literal maps are declared in curly braces much like property maps. Lists are supported.

WITH {name: 'Alice', age: 20, colors: ['blue', 'green']} AS map
RETURN map.name, map.age, map.colors[0]

Map entries can be accessed by their keys. Invalid keys result in an error.

WITH {person: {name: 'Anne', age: 25}} AS p
RETURN p.person.name AS name

Access the property of a nested map.

MERGE (p:Person {name: $map.name})
ON CREATE SET p = $map

Maps can be passed in as parameters and used either as a map or by accessing keys.

MATCH (matchedNode:Person)
RETURN matchedNode

Nodes and relationships are returned as maps of their data.

Predicates

n.property <> $value

Use comparison operators.

toString(n.property) = $value

Use functions.

n.number >= 1 AND n.number <= 10

Use boolean operators to combine predicates.

n:Person

Check for node labels.

variable IS NOT NULL

Check if something is not null, e.g. that a property exists.

n.property IS NULL OR n.property = $value

Either the property does not exist or the predicate is true.

n.property = $value

Non-existing property returns null, which is not equal to anything.

n['property'] = $value

Properties may also be accessed using a dynamically computed property name.

n.property STARTS WITH 'Neo'

String matching that starts with the specified string.

n.property ENDS WITH '4j'

String matching that ends with the specified string.

n.property CONTAINS 'cypher'

String matching that contains the specified string.

n.property =~ '(?i)neo.*'

String matching that matches the specified regular expression. By prepending a regular expression with (?i), the whole expression becomes case-insensitive.

(n:Person)-[:KNOWS]->(m:Person)

Ensure the pattern has at least one match.

NOT (n:Person)-[:KNOWS]->(m:Person)

Exclude matches to (n:Person)-[:KNOWS]→(m:Person) from the result.

n.property IN [$value1, $value2]

Check if an element exists in a list.

List Expressions

[x IN list | x.prop]

A list of the value of the expression for each element in the original list.

[x IN list WHERE x.prop <> $value]

A filtered list of the elements where the predicate is true.

[x IN list WHERE x.prop <> $value | x.prop]

A list comprehension that filters a list and extracts the value of the expression for each element in that list.

Expressions

CASE expressions

CASE n.eyes
  WHEN 'blue' THEN 1
  WHEN 'brown' THEN 2
  ELSE 3
END

The CASE expression can be used in expression positions, for example as part of the WITH or RETURN clauses.

Return THEN value from the matching WHEN value. The ELSE value is optional, and substituted for null if missing.

CASE
  WHEN n.eyes = 'blue' THEN 1
  WHEN n.age < 40 THEN 2
  ELSE 3
END

Return THEN value from the first WHEN predicate evaluating to true. Predicates are evaluated in order.

MATCH (n)-[r]->(m)
RETURN
CASE
  WHEN n:A&B THEN 1
  WHEN r:!R1&!R2 THEN 2
  ELSE -1
END AS result

A relationship type expression and a label expression can be used in a CASE expression.

Type predicate expressions

n.property IS :: INTEGER

Verify that the property is of a certain type.

n.property IS :: INTEGER NOT NULL

Verify that the property is of a certain type, and that it is not null.

n.property IS :: INTEGER!

Adding an exclamation mark after the value type is a synonym to NOT NULL. It can also be used to verify that the property is of a certain type and that it is not null.

variable IS NOT :: STRING

Verify that the variable is not of a certain type.

Functions

Aggregating functions

MATCH (p:Person)
RETURN avg(p.age)

The avg function returns the average of a set of INTEGER or FLOAT values.

UNWIND [duration('P2DT3H'), duration('PT1H45S')] AS dur
RETURN avg(dur)

The avg duration function returns the average of a set of DURATION values.

MATCH (p:Person)
RETURN collect(p.age)

The collect function returns a single aggregated list containing the non-null values returned by an expression.

MATCH (p:Person {name: 'Keanu Reeves'})-->(x)
RETURN labels(p), p.age, count(*)

The count function returns the number of values or rows. When count(*) is used, the function returns the number of matching rows.

MATCH (p:Person)
RETURN count(p.age)

The count function can also be passed an expression. If so, it returns the number of non-null values returned by the given expression.

MATCH (p:Person)
RETURN max(p.age)

The max function returns the maximum value in a set of values.

MATCH (p:Person)
RETURN min(p.age)

The min function returns the minimum value in a set of values.

MATCH (p:Person)
RETURN percentileCont(p.age, 0.4)

The percentileCont function returns the percentile of the given value over a group, with a percentile from 0.0 to 1.0. It uses a linear interpolation method, calculating a weighted average between two values if the desired percentile lies between them.

MATCH (p:Person)
RETURN percentileDisc(p.age, 0.5)

The percentileDisc function returns the percentile of the given value over a group, with a percentile from 0.0 to 1.0. It uses a rounding method and calculates the nearest value to the percentile.

MATCH (p:Person)
WHERE p.name IN ['Keanu Reeves', 'Liam Neeson', 'Carrie Anne Moss']
RETURN stDev(p.age)

The stDev function returns the standard deviation for the given value over a group. It uses a standard two-pass method, with N - 1 as the denominator, and should be used when taking a sample of the population for an unbiased estimate.

MATCH (p:Person)
RETURN stDevP(p.age)

The stDevP function returns the standard deviation for the given value over a group. It uses a standard two-pass method, with N as the denominator, and should be used when calculating the standard deviation for an entire population.

MATCH (p:Person)
RETURN sum(p.age)

The sum function returns the sum of a set of numeric values.

UNWIND [duration('P2DT3H'), duration('PT1H45S')] AS dur
RETURN sum(dur)

The sum duration function returns the sum of a set of durations.

Database functions

WITH "2:efc7577d-022a-107c-a736-dbcdfc189c03:0" AS eid
RETURN db.nameFromElementId(eid) AS name

The db.nameFromElementId function returns the name of a database to which the element id belongs. The name of the database can only be returned if the provided element id belongs to a standard database in the DBMS.

Duration functions

UNWIND [
duration({days: 14, hours:16, minutes: 12}),
duration({months: 0.75}),
duration({weeks: 2.5}),
duration({minutes: 1.5, seconds: 1, milliseconds: 123, microseconds: 456, nanoseconds: 789}),
] AS aDuration
RETURN aDuration

The duration function can construct a DURATION from a MAP of its components.

RETURN duration('P1Y2M10DT12H45M30.25S') AS duration

The duration from a string function returns the DURATION value obtained by parsing a STRING representation of a temporal amount.

UNWIND [
duration.between(date("1984-10-11"), date("1985-11-25")),
duration.between(date("1984-10-11"), datetime("1984-10-12T21:40:32.142+0100")),
duration.between(date("2015-06-24"), localtime("14:30")),
duration.between(localtime("14:30"), time("16:30+0100")),
duration.between(localdatetime("2015-07-21T21:40:32.142"), localdatetime("2016-07-21T21:45:22.142"))
] AS aDuration
RETURN aDuration

The duration.between function returns the DURATION value equal to the difference between the two given instants.

UNWIND [
duration.inDays(date("1984-10-11"), date("1985-11-25")),
duration.inDays(date("1984-10-11"), datetime("1984-10-12T21:40:32.142+0100")),
duration.inDays(date("2015-06-24"), localtime("14:30")),
duration.inDays(localdatetime("2015-07-21T21:40:32.142"), localdatetime("2016-07-21T21:45:22.142"))
] AS aDuration
RETURN aDuration

The duration.inDays function returns the DURATION value equal to the difference in whole days or weeks between the two given instants.

UNWIND [
duration.inMonths(date("1984-10-11"), date("1985-11-25")),
duration.inMonths(date("1984-10-11"), datetime("1984-10-12T21:40:32.142+0100")),
duration.inMonths(date("2015-06-24"), localtime("14:30")),
duration.inMonths(localdatetime("2015-07-21T21:40:32.142"), localdatetime("2016-07-21T21:45:22.142"))
] AS aDuration
RETURN aDuration

The duration.inMonths function returns the DURATION value equal to the difference in whole months between the two given instants.

UNWIND [
duration.inSeconds(date("1984-10-11"), date("1984-10-12")),
duration.inSeconds(date("1984-10-11"), datetime("1984-10-12T01:00:32.142+0100")),
duration.inSeconds(date("2015-06-24"), localtime("14:30"))
] AS aDuration
RETURN aDuration

The duration.inSeconds function returns the DURATION value equal to the difference in seconds and nanoseconds between the two given instants.

Graph functions

RETURN graph.names() AS name

The graph.names function returns a list containing the names of all graphs on the current composite database. It is only supported on composite databases.

RETURN graph.propertiesByNames() AS name

The graph.propertiesByNames function returns a map containing the properties associated with the given graph. The properties are set on the alias that adds the graph as a constituent of a composite database. It is only supported on composite databases.

UNWIND graph.names() AS graphName
CALL {
  USE graph.byName(graphName)
  MATCH (n)
  RETURN n
}
RETURN n

The graph.byName function resolves a constituent graph by name. It is only supported in the USE clause on composite databases.

USE graph.byElementId("4:c0a65d96-4993-4b0c-b036-e7ebd9174905:0")
MATCH (n)
RETURN n

The graph.byElementId function is used in the USE clause to resolve a constituent graph to which a given element id belongs. If the constituent database is not a standard database in the DBMS, an error will be thrown.

List functions

MATCH (a) WHERE a.name = 'Alice'
RETURN keys(a)

The keys function returns a LIST<STRING> containing the STRING representations for all the property names of a NODE, RELATIONSHIP, or MAP.

MATCH (a) WHERE a.name = 'Alice'
RETURN labels(a)

The labels function returns a LIST<STRING> containing the STRING representations for all the labels of a NODE.

MATCH p = (a)-->(b)-->(c)
WHERE a.name = 'Alice' AND c.name = 'Eskil'
RETURN nodes(p)

The nodes function returns a LIST<NODE> containing all the NODE values in a PATH.

RETURN range(0, 10), range(2, 18, 3), range(0, 5, -1)

The range function returns a LIST<INTEGER> comprising all INTEGER values within a range bounded by a start value and an end value, where the difference step between any two consecutive values is constant; i.e. an arithmetic progression.

MATCH p = (a)-->(b)-->(c)
WHERE a.name = 'Alice' AND b.name = 'Bob' AND c.name = 'Daniel'
RETURN reduce(totalAge = 0, n IN nodes(p) | totalAge + n.age) AS reduction

The reduce function returns the value resulting from the application of an expression on each successive element in a list in conjunction with the result of the computation thus far.

MATCH p = (a)-->(b)-->(c)
WHERE a.name = 'Alice' AND c.name = 'Eskil'
RETURN relationships(p)

The relationships function returns a LIST<RELATIONSHIP> containing all the RELATIONSHIP values in a PATH.

WITH [4923,'abc',521, null, 487] AS ids
RETURN reverse(ids)

The reverse function returns a LIST<ANY> in which the order of all elements in the given LIST<ANY> have been reversed.

MATCH (a) WHERE a.name = 'Eskil'
RETURN a.array, tail(a.array)

The tail function returns a LIST<ANY> containing all the elements, excluding the first one, from a given LIST<ANY>.

RETURN toBooleanList([null, null]) as nullsInList,
toBooleanList(['a string', true, 'false', null, ['A','B']]) as mixedList

The toBooleanList converts a LIST<ANY> and returns a LIST<BOOLEAN>. If any values are not convertible to BOOLEAN they will be null in the LIST<BOOLEAN> returned.

RETURN toFloatList(null) as noList,
toFloatList([null, null]) as nullsInList,
toFloatList(['a string', 2.5, '3.14159', null, ['A','B']]) as mixedList

The toFloatList converts a LIST<ANY> of values and returns a LIST<FLOAT>. If any values are not convertible to FLOAT they will be null in the LIST<FLOAT> returned.

RETURN toIntegerList(null) as noList,
toIntegerList([null, null]) as nullsInList,
toIntegerList(['a string', 2, '5', null, ['A','B']]) as mixedList

The toIntegerList converts a LIST<ANY> of values and returns a LIST<INTEGER>. If any values are not convertible to INTEGER they will be null in the LIST<INTEGER> returned.

RETURN toStringList(null) as noList,
toStringList([null, null]) as nullsInList,
toStringList(['already a string', 2, date({year:1955, month:11, day:5}), null, ['A','B']]) as mixedList

The toStringList converts a LIST<ANY> of values and returns a LIST<STRING>. If any values are not convertible to STRING they will be null in the LIST<STRING> returned.

Mathematical functions - numerical

MATCH (a), (e)
WHERE a.name = 'Alice' AND e.name = 'Eskil'
RETURN a.age, e.age, abs(a.age - e.age)

The abs function returns the absolute value of the given number.

RETURN ceil(0.1)

The ceil function returns the smallest FLOAT that is greater than or equal to the given number and equal to an INTEGER.

RETURN floor(0.9)

The floor function returns the largest FLOAT that is less than or equal to the given number and equal to an INTEGER.

RETURN isNaN(0/0.0)

The isNan function returns true if the given numeric value is NaN (Not a Number).

RETURN rand() AS random

The rand function returns a random FLOAT in the range from 0 (inclusive) to 1 (exclusive). The numbers returned follow an approximate uniform distribution.

RETURN round(3.141592)

The round function returns the value of the given number rounded to the nearest INTEGER, with ties always rounded towards positive infinity.

RETURN round(3.141592, 3)

The round with precision function returns the value of the given number rounded to the closest value of given precision, with ties always being rounded away from zero (using rounding mode HALF_UP). The exception is for precision 0, where ties are rounded towards positive infinity to align with round() without precision.

RETURN round(1.249, 1, 'UP') AS positive,
round(-1.251, 1, 'UP') AS negative,
round(1.25, 1, 'DOWN') AS positiveTie,
round(-1.35, 1, 'DOWN') AS negativeTie

The round with precision and rounding mode function returns the value of the given number rounded with the specified precision and the specified rounding mode.

RETURN sign(-17), sign(0.1)

The sign function returns the signum of the given number: 0 if the number is 0, -1 for any negative number, and 1 for any positive number.

Mathematical functions - logarithmic

RETURN e()

The e function returns the base of the natural logarithm, e.

RETURN exp(2)

The exp function returns en, where e is the base of the natural logarithm, and n is the value of the argument expression.

RETURN log(27)

The log function returns the natural logarithm of a number.

RETURN log10(27)

The log10 function returns the common logarithm (base 10) of a number.

RETURN sqrt(256)

The sqrt function returns the square root of a number.

Mathematical Functions - trigonometric

RETURN acos(0.5)

The acos function returns the arccosine of a FLOAT in radians.

RETURN asin(0.5)

The asin function returns the arcsine of a FLOAT in radians.

RETURN atan(0.5)

The atan function returns the arctangent of a FLOAT in radians.

RETURN atan2(0.5, 0.6)

The atan2 function returns the arctangent2 of a set of coordinates in radians.

RETURN cos(0.5)

The cos function returns the cosine of a FLOAT.

RETURN cot(0.5)

The cot function returns the cotangent of a FLOAT.

RETURN degrees(3.14159)

The degrees function converts radians to degrees.

RETURN haversin(0.5)

The haversin function converts half the versine of a number.

RETURN pi()

The pi function returns the mathematical constant pi.

RETURN radians(180)

The radians function converts degrees to radians.

RETURN sin(0.5)

The sin function returns the sine of a number.

RETURN tan(0.5)

The tan function returns the tangent of a number.

Predicate functions

MATCH p = (a)-[*]->(b)
WHERE
  a.name = 'Keanu Reeves'
  AND b.name = 'Guy Pearce'
  AND all(x IN nodes(p) WHERE x.age < 60)
RETURN p

The all function returns true if the predicate holds for all elements in the given LIST<ANY>.

MATCH (p:Person)
WHERE any(nationality IN p.nationality WHERE nationality = 'American')
RETURN p

The any function returns true if the predicate holds for at least one element in the given LIST<ANY>.

MATCH (p:Person)
RETURN
  p.name AS name,
  exists((p)-[:ACTED_IN]->()) AS has_acted_in_rel

The exists function returns true if a match for the given pattern exists in the graph.

MATCH (p:Person)
WHERE NOT isEmpty(p.nationality)
RETURN p.name, p.nationality

The isEmpty function returns true if the given LIST<ANY> or MAP contains no elements, or if the given STRING contains no characters.

MATCH p = (n)-[*]->(b)
WHERE
  n.name = 'Keanu Reeves'
  AND none(x IN nodes(p) WHERE x.age > 60)
RETURN p

The none function returns true if the predicate does not hold for any element in the given LIST<ANY>.

MATCH p = (n)-->(b)
WHERE
  n.name = 'Keanu Reeves'
  AND single(x IN nodes(p) WHERE x.nationality = 'Northern Irish')
RETURN p

The single function returns true if the predicate holds for exactly one of the elements in the given LIST<ANY>.

Scalar functions

RETURN char_length('Alice')

The char_length function returns the number of Unicode characters in a STRING. This function is an alias of the size function.

RETURN character_length('Alice')

The character_length function returns the number of Unicode characters in a STRING. This function is an alias of the size function.

MATCH (a)
WHERE a.name = 'Alice'
RETURN coalesce(a.hairColor, a.eyes)

The coalesce function returns the first given non-null argument.

MATCH (a)
RETURN elementId(a)

The elementId function returns a STRING representation of a node or relationship identifier, unique within a specific transaction and DBMS.

MATCH (x:Developer)-[r]-()
RETURN endNode(r)

The endNode function returns the the end NODE of a RELATIONSHIP.

MATCH (a)
WHERE a.name = 'Eskil'
RETURN a.liked_colors, head(a.liked_colors)

The head function returns the first element of the list. Returns null for an empty list. Equivalent to the list indexing $list[0].

MATCH (a)
RETURN id(a)

The id function returns an INTEGER (the internal ID of a node or relationship). Do not rely on the internal ID for your business domain; the internal ID can change between transactions. The id function will be removed in the next major release. It is recommended to use elementId instead.

MATCH (a)
WHERE a.name = 'Eskil'
RETURN a.liked_colors, last(a.liked_colors)

The last function returns the last element of the list. Returns null for an empty list. Equivalent to the list indexing $list[-1].

MATCH p = (a)-->(b)-->(c)
WHERE a.name = 'Alice'
RETURN length(p)

The length function returns the length of a PATH.

RETURN nullIf("abc", "def")

The nullIf function returns null if the two given parameters are equivalent, otherwise it returns the value of the first parameter.

CREATE (p:Person {name: 'Stefan', city: 'Berlin'})
RETURN properties(p)

The properties function returns a MAP containing all the properties of a node or relationship.

RETURN randomUUID() AS uuid

The randomUUID function returns a STRING; a randomly-generated universally unique identifier (UUID).

RETURN size(['Alice', 'Bob'])

The size function returns the number of elements in the list.

MATCH (x:Developer)-[r]-()
RETURN startNode(r)

The function startNode function returns the start NODE of a RELATIONSHIP.

RETURN timestamp()

The timestamp function returns the time in milliseconds since midnight, January 1, 1970 UTC. and the current time.

RETURN toBoolean('true'), toBoolean('not a boolean'), toBoolean(0)

The toBoolean function converts a STRING, INTEGER or BOOLEAN value to a BOOLEAN value.

RETURN toBooleanOrNull('true'), toBooleanOrNull('not a boolean'), toBooleanOrNull(0), toBooleanOrNull(1.5)

The toBooleanOrNull function converts a STRING, INTEGER or BOOLEAN value to a BOOLEAN value. For any other input value, null will be returned.

RETURN toFloat('11.5'), toFloat('not a number')

The toFloat function converts an INTEGER, FLOAT or a STRING value to a FLOAT.

RETURN toFloatOrNull('11.5'), toFloatOrNull('not a number'), toFloatOrNull(true)

The toFloatOrNull function converts an INTEGER, FLOAT or a STRING value to a FLOAT. For any other input value, null will be returned.

RETURN toInteger('42'), toInteger('not a number'), toInteger(true)

The toInteger function converts a BOOLEAN, INTEGER, FLOAT or a STRING value to an INTEGER value.

RETURN toIntegerOrNull('42'), toIntegerOrNull('not a number'), toIntegerOrNull(true), toIntegerOrNull(['A', 'B', 'C'])

The toIntegerOrNull function converts a BOOLEAN, INTEGER, FLOAT or a STRING value to an INTEGER value. For any other input value, null will be returned.

MATCH (n)-[r]->()
WHERE n.name = 'Alice'
RETURN type(r)

The type function returns the STRING representation of the RELATIONSHIP type.

UNWIND ["abc", 1, 2.0, true, [date()]] AS value
RETURN valueType(value) AS result

The valueType function returns a STRING representation of the most precise value type that the given expression evaluates to.

String functions

RETURN btrim('   hello    '), btrim('xxyyhelloxyxy', 'xy')

The btrim function returns the original STRING with leading and trailing trimCharacterString characters removed. If trimCharacterString is not specified then all leading and trailing whitespace will be removed.

RETURN left('hello', 3)

The left function returns a STRING containing the specified number of leftmost characters of the given STRING.

RETURN ltrim('   hello'), ltrim('xxyyhelloxyxy', 'xy')

The ltrim function returns the original STRING with leading trimCharacterString characters removed. If trimCharacterString is not specified then all leading whitespace will be removed.

RETURN replace("hello", "l", "w")

The replace function returns a STRING in which all occurrences of a specified STRING in the given STRING have been replaced by another (specified) replacement STRING.

RETURN reverse('palindrome')

The reverse function returns a STRING in which the order of all characters in the given STRING have been reversed.

RETURN right('hello', 3)

The right function returns a STRING containing the specified number of rightmost characters in the given STRING.

RETURN rtrim('hello   '), rtrim('xxyyhelloxyxy', 'xy')

The rtrim function returns the given STRING with trailing trimCharacterString characters removed. If trimCharacterString is not specified then all trailing whitespace will be removed.

RETURN split('one,two', ',')

The split function returns a LIST<STRING> resulting from the splitting of the given STRING around matches of the given delimiter.

RETURN substring('hello', 1, 3), substring('hello', 2)

The substring function returns a substring of the given STRING, beginning with a zero-based index start and length.

RETURN toLower('HELLO')

The toLower function returns the given STRING in lowercase.

RETURN
  toString(11.5),
  toString('already a string'),
  toString(true),
  toString(date({year: 1984, month: 10, day: 11})) AS dateString,
  toString(datetime({year: 1984, month: 10, day: 11, hour: 12, minute: 31, second: 14, millisecond: 341, timezone: 'Europe/Stockholm'})) AS datetimeString,
  toString(duration({minutes: 12, seconds: -60})) AS durationString

The toString function converts an INTEGER, FLOAT, BOOLEAN, STRING, POINT, DURATION, DATE, ZONED TIME, LOCAL TIME, LOCAL DATETIME or ZONED DATETIME value to a STRING.

RETURN
  toString(11.5),
  toString('already a string'),
  toString(true),
  toString(date({year: 1984, month: 10, day: 11})) AS dateString,
  toString(datetime({year: 1984, month: 10, day: 11, hour: 12, minute: 31, second: 14, millisecond: 341, timezone: 'Europe/Stockholm'})) AS datetimeString,
  toString(duration({minutes: 12, seconds: -60})) AS durationString

The toStringOrNull function converts an INTEGER, FLOAT, BOOLEAN, STRING, POINT, DURATION, DATE, ZONED TIME, LOCAL TIME, LOCAL DATETIME or ZONED DATETIME value to a STRING. For any other input value, null will be returned.

RETURN toUpper('hello')

The toUpper function returns the given STRING in uppercase.

RETURN trim('   hello   ')

The trim function returns the given STRING with leading and trailing whitespace removed.

Spatial functions

RETURN point({x: 2.3, y: 4.5}) AS point

The point Cartesian 2D function returns a 2D POINT in the Cartesian CRS corresponding to the given coordinate values.

RETURN point({x: 2.3, y: 4.5, z: 2}) AS point

The point Cartesian 3D function returns a 3D POINT in the Cartesian CRS corresponding to the given coordinate values.

MATCH (p:Office)
RETURN point({longitude: p.longitude, latitude: p.latitude}) AS officePoint

The point WGS 84 2D function returns a 2D POINT in the WGS 84 CRS corresponding to the given coordinate values.

RETURN point({longitude: 56.7, latitude: 12.78, height: 8}) AS point

The point WGS 84 3D function returns a 3D POINT in the WGS 84 CRS corresponding to the given coordinate values.

MATCH (t:TrainStation)-[:TRAVEL_ROUTE]->(o:Office)
WITH
  point({longitude: t.longitude, latitude: t.latitude}) AS trainPoint,
  point({longitude: o.longitude, latitude: o.latitude}) AS officePoint
RETURN round(point.distance(trainPoint, officePoint)) AS travelDistance

The point.distance function returns returns a FLOAT representing the geodesic distance between two points in the same Coordinate Reference System (CRS).

WITH
  point({longitude: 12.53, latitude: 55.66}) AS lowerLeft,
  point({longitude: 12.614, latitude: 55.70}) AS upperRight
MATCH (t:TrainStation)
WHERE point.withinBBox(point({longitude: t.longitude, latitude: t.latitude}), lowerLeft, upperRight)
RETURN count(t)

The point.withinBBox function takes the following arguments: the POINT to check, the lower-left (south-west) POINT of a bounding box, and the upper-right (or north-east) POINT of a bounding box. The return value will be true if the provided point is contained in the bounding box (boundary included), otherwise the return value will be false.

Temporal functions

RETURN date() AS currentDate

The date function returns the current DATE value. If no time zone parameter is specified, the local time zone will be used.

RETURN date.transaction() AS currentDate

The date.transaction function returns the current DATE value using the transaction clock. This value will be the same for each invocation within the same transaction. However, a different value may be produced for different transactions.

RETURN date.statement() AS currentDate

The date.statement function returns the current DATE value using the statement clock. This value will be the same for each invocation within the same statement. However, a different value may be produced for different statements within the same transaction.

RETURN date.realtime() AS currentDate

The date.realtime function returns returns the current DATE value using the realtime clock. This value will be the live clock of the system.

RETURN datetime() AS currentDateTime

The datetime function returns the current ZONED DATETIME value. If no time zone parameter is specified, the default time zone will be used.

RETURN datetime.transaction() AS currentDateTime

The datetime.transaction function returns the current ZONED DATETIME value using the transaction clock. This value will be the same for each invocation within the same transaction. However, a different value may be produced for different transactions.

RETURN datetime.statement() AS currentDateTime

The datetime.statement function returns the current ZONED DATETIME value using the transaction clock. This value will be the same for each invocation within the same transaction. However, a different value may be produced for different transactions.

RETURN datetime.realtime() AS currentDateTime

The datetime.realtime function returns the current ZONED DATETIME value using the realtime clock. This value will be the live clock of the system.

RETURN localdatetime() AS now

The localdatetime function returns the current LOCAL DATETIME value. If no time zone parameter is specified, the local time zone will be used.

RETURN localdatetime.transaction() AS now

The localdatetime.transaction function returns the current LOCAL DATETIME value using the transaction clock. This value will be the same for each invocation within the same transaction. However, a different value may be produced for different transactions.

RETURN localdatetime.statement() AS now

The localdatetime.statement function returns the current LOCAL DATETIME value using the statement clock. This value will be the same for each invocation within the same statement. However, a different value may be produced for different statements within the same transaction.

RETURN localdatetime.realtime() AS now

The localdatetime.realtime function returns the current LOCAL DATETIME value using the realtime clock. This value will be the live clock of the system.

RETURN localtime() AS now

The localtime function returns the current LOCAL TIME value. If no time zone parameter is specified, the local time zone will be used.

RETURN localtime.transaction() AS now

The localtime.transaction function returns the current LOCAL TIME value using the transaction clock. This value will be the same for each invocation within the same transaction. However, a different value may be produced for different transactions.

RETURN localtime.statement() AS now

The localtime.statement function returns the current LOCAL TIME value using the statement clock. This value will be the same for each invocation within the same statement. However, a different value may be produced for different statements within the same transaction.

RETURN localtime.realtime() AS now

The localtime.realtime function returns the current LOCAL TIME value using the realtime clock. This value will be the live clock of the system.

RETURN time() AS now

The time function returns the current ZONED TIME value. If no time zone parameter is specified, the local time zone will be used.

RETURN time.transaction() AS now

The time.transaction function returns the current ZONED TIME value using the transaction clock. This value will be the same for each invocation within the same transaction. However, a different value may be produced for different transactions.

RETURN time.statement() AS now

The time.statement function returns the current ZONED TIME value using the statement clock. This value will be the same for each invocation within the same statement. However, a different value may be produced for different statements within the same transaction.

RETURN time.realtime() AS now

The time.realtime function returns the current ZONED TIME value using the realtime clock. This value will be the live clock of the system.

Vector functions

MATCH (n:Label)
WITH n, vector.similarity.euclidean($query, n.vector) AS score
RETURN n, score

The vector.similarity.euclidean function returns a FLOAT representing the similarity between the argument vectors based on their Euclidean distance.

MATCH (n:Label)
WITH n, vector.similarity.cosine($query, n.vector) AS score
RETURN n, score

The vector.similarity.cosine function returns a FLOAT representing the similarity between the argument vectors based on their cosine.

Schema

Search-performance indexes

Cypher includes four search-performance indexes: range (default), text, point, and token lookup.

CREATE INDEX index_name
FOR (p:Person) ON (p.name)

Create a range index with the name index_name on nodes with label Person and property name.

It is possible to omit the index_name, if not specified the index name will be decided by the DBMS. Best practice is to always specify a sensible name when creating an index.

The create syntax is CREATE [RANGE|TEXT|POINT|LOOKUP|FULLTEXT|VECTOR] INDEX …​. Defaults to range if not explicitly stated.

CREATE RANGE INDEX index_name
FOR ()-[k:KNOWS]-() ON (k.since)

Create a range index on relationships with type KNOWS and property since with the name index_name.

CREATE INDEX $nameParam
FOR (p:Person) ON (p.name, p.age)

Create a composite range index with the name given by the parameter nameParam on nodes with label Person and the properties name and age, throws an error if the index already exist.

CREATE INDEX index_name IF NOT EXISTS
FOR (p:Person) ON (p.name, p.age)

Create a composite range index with the name index_name on nodes with label Person and the properties name and age if it does not already exist, does nothing if it did exist.

CREATE TEXT INDEX index_name
FOR (p:Person) ON (p.name)

Create a text index on nodes with label Person and property name. Text indexes only solve predicates involving STRING property values.

CREATE TEXT INDEX index_name
FOR ()-[r:KNOWS]-() ON (r.city)

Create a text index on relationships with type KNOWS and property city. Text indexes only solve predicates involving STRING property values.

CREATE POINT INDEX index_name
FOR (p:Person) ON (p.location)
OPTIONS {
  indexConfig: {
    `spatial.cartesian.min`: [-100.0, -100.0],
    `spatial.cartesian.max`: [100.0, 100.0]
  }
}

Create a point index on nodes with label Person and property location with the name index_name and the given spatial.cartesian settings. The other index settings will have their default values. Point indexes only solve predicates involving POINT property values.

CREATE POINT INDEX $nameParam
FOR ()-[h:STREET]-() ON (h.intersection)

Create a point index with the name given by the parameter nameParam on relationships with the type STREET and property intersection. Point indexes only solve predicates involving POINT property values.

CREATE LOOKUP INDEX index_name
FOR (n) ON EACH labels(n)

Create a token lookup index on nodes with any label.

CREATE LOOKUP INDEX index_name
FOR ()-[r]-() ON EACH type(r)

Create a token lookup index on relationships with any relationship type.

SHOW INDEXES

List all indexes, returns only the default outputs (id, name, state, populationPercent, type, entityType, labelsOrTypes, properties, indexProvider, owningConstraint, lastRead, and readCount).

SHOW INDEXES YIELD *

List all indexes and return all columns.

SHOW INDEX YIELD name, type, entityType, labelsOrTypes, properties

List all indexes and return only specific columns.

SHOW INDEXES
YIELD name, type, options, createStatement
RETURN name, type, options.indexConfig AS config, createStatement

List all indexes and return only specific columns using the RETURN clause. Note that YIELD is mandatory if RETURN is used.

SHOW RANGE INDEXES

List range indexes, can also be filtered on ALL, FULLTEXT, LOOKUP, POINT, TEXT, and VECTOR.

DROP INDEX index_name

Drop the index named index_name, throws an error if the index does not exist.

DROP INDEX index_name IF EXISTS

Drop the index named index_name if it exists, does nothing if it does not exist.

DROP INDEX $nameParam

Drop an index using a parameter.

MATCH (n:Person)
USING INDEX n:Person(name)
WHERE n.name = $value

Index usage can be enforced when Cypher uses a suboptimal index, or when more than one index should be used.

Full-text indexes

CREATE FULLTEXT INDEX node_fulltext_index
FOR (n:Friend) ON EACH [n.name]
OPTIONS {
  indexConfig: {
    `fulltext.analyzer`: 'swedish'
  }
}

Create a fulltext index on nodes with the name index_name and analyzer swedish. The other index settings will have their default values.

CREATE FULLTEXT INDEX relationship_fulltext_index
FOR ()-[r:KNOWS]-() ON EACH [r.info, r.note]
OPTIONS {
  indexConfig: {
    `fulltext.analyzer`: 'english'
  }
}

Create a fulltext index on relationships with the name index_name and analyzer english. The other index settings will have their default values.

CALL db.index.fulltext.queryNodes("node_fulltext_index", "Alice") YIELD node, score

Query a full-text index on nodes.

CALL db.index.fulltext.queryRelationships("relationship_fulltext_index", "Alice") YIELD relationship, score

Query a full-text index on relationships.

SHOW FULLTEXT INDEXES

List all full-text indexes.

DROP INDEX node_fulltext_index

Drop a full-text index.

Vector indexes

CREATE VECTOR INDEX `abstract-embeddings`
FOR (a:Abstract) ON (a.embedding)
OPTIONS {
  indexConfig: {
    `vector.dimensions`: 1536,
    `vector.similarity_function`: 'cosine'
  }
}

Create a vector index on nodes with label Abstract, property embedding, and a vector dimension of 1536 using the cosine similarity function and the name abstract-embeddings. Note that the OPTIONS map is mandatory since a vector index cannot be created without setting the vector dimensions and similarity function.

CREATE VECTOR INDEX `review-embeddings`
FOR ()-[r:REVIEWED]-() ON (r.embedding)
OPTIONS {
  indexConfig: {
    `vector.dimensions`: 256,
    `vector.similarity_function`: 'cosine'
  }
}

Create a vector index on relationships with relationship type REVIEWED, property embedding, and a vector dimension of 256 using the cosine similarity function and the name review-embeddings. Note that the OPTIONS map is mandatory since a vector index cannot be created without setting the vector dimensions and similarity function.

CALL db.index.vector.queryNodes('abstract-embeddings', 10, abstract.embedding)

Query the node vector index abstract-embeddings for a neighborhood of 10 similar abstracts.

CALL db.index.vector.queryRelationships('review-embeddings', 10, $query)

Query the relationship vector index review-embeddings for a neighborhood of 10 similar reviews to the vector given by the query parameter.

MATCH (n:Node {id: $id})
CALL db.create.setNodeVectorProperty(n, 'propertyKey', $vector)

Set the vector properties of a node using db.create.setNodeVectorProperty.

MATCH ()-[r:Relationship {id: $id}]->()
CALL db.create.setRelationshipVectorProperty(r, 'propertyKey', $vector)

Set the vector properties of a relationship using db.create.setRelationshipVectorProperty.

SHOW VECTOR INDEXES

List all vector indexes.

DROP INDEX `abstract-embeddings`

Drop a vector index.

Constraints

SHOW ALL CONSTRAINTS

List all constraints, returns only the default outputs (id, name, type, entityType, labelsOrTypes, properties, ownedIndex, and propertyType). Can also be filtered on NODE UNIQUENESS, RELATIONSHIP UNIQUENESS, UNIQUENESS, NODE EXISTENCE, RELATIONSHIP EXISTENCE, EXISTENCE, NODE PROPERTY TYPE, RELATIONSHIP PROPERTY TYPE, PROPERTY TYPE, NODE KEY, RELATIONSHIP KEY, and KEY. For more information, see Constraints → Syntax → SHOW CONSTRAINTS.

SHOW CONSTRAINTS YIELD *

List all constraints. For more information, see Constraints → Create, show, and drop constraints → SHOW CONSTRAINTS.

DROP CONSTRAINT constraint_name

Drop the constraint with the name constraint_name, throws an error if the constraint does not exist.

DROP CONSTRAINT $nameParam IF EXISTS

Drop the constraint with the name given by the parameter nameParam if it exists, does nothing if it does not exist.

CREATE CONSTRAINT constraint_name IF NOT EXISTS
FOR (p:Person)
REQUIRE p.name IS UNIQUE

Create a node property uniqueness constraint on the label Person and property name. Using the keyword IF NOT EXISTS makes the command idempotent, and no error will be thrown if an attempt is made to create the same constraint twice. If any other node with that label is updated or created with a name that already exists, the write operation will fail.

Best practice is to always specify a sensible name when creating a constraint.

CREATE CONSTRAINT constraint_name
FOR (p:Person)
REQUIRE (p.name, p.age) IS UNIQUE

Create a node property uniqueness constraint on the label Person and properties name and age. An error will be thrown if an attempt is made to create the same constraint twice. If any node with that label is updated or created with a name and age combination that already exists, the write operation will fail.

CREATE CONSTRAINT constraint_name
FOR (p:Person)
REQUIRE p.surname IS UNIQUE
OPTIONS {
  indexProvider: 'range-1.0'
}

Create a node property uniqueness constraint on the label Person and property surname with the index provider range-1.0 for the accompanying index.

CREATE CONSTRAINT constraint_name
FOR ()-[r:LIKED]-()
REQUIRE r.when IS UNIQUE

Create a relationship property uniqueness constraint on the relationship type LIKED and property when. If any other relationship with that relationship type is updated or created with a when property value that already exists, the write operation will fail.

Best practice is to always specify a sensible name when creating a constraint.

CREATE CONSTRAINT $nameParam
FOR (p:Person)
REQUIRE p.name IS NOT NULL

Create a node property existence constraint with the name given by the parameter nameParam on the label Person and property name. If a node with that label is created without a name property, or if the name property on the existing node with the label Person is removed, the write operation will fail.

CREATE CONSTRAINT constraint_name
FOR ()-[r:LIKED]-()
REQUIRE r.when IS NOT NULL

Create a relationship property existence constraint on the type LIKED and property when. If a relationship with that type is created without a when property, or if the property when is removed from an existing relationship with the type LIKED, the write operation will fail.

CREATE CONSTRAINT constraint_name
FOR (p:Person)
REQUIRE p.name IS :: STRING

Create a node property type constraint on the label Person and property name, restricting the property to STRING. If a node with that label is created with a name property of a different Cypher type, the write operation will fail.

CREATE CONSTRAINT constraint_name
FOR ()-[r:LIKED]-()
REQUIRE r.when IS :: DATE

Create a relationship property type constraint on the type LIKED and property when, restricting the property to DATE. If a relationship with that type is created with a when property of a different Cypher type, the write operation will fail.

CREATE CONSTRAINT constraint_name
FOR (p:Person)
REQUIRE (p.name, p.surname) IS NODE KEY

Create a node key constraint on the label Person and properties name and surname with the name constraint_name. If a node with that label is created without both the name and surname properties, or if the combination of the two is not unique, or if the name and/or surname properties on an existing node with the label Person is modified to violate these constraints, the write operation will fail.

CREATE CONSTRAINT constraint_name
FOR (p:Person)
REQUIRE (p.name, p.age) IS NODE KEY
OPTIONS {
  indexProvider: 'range-1.0'
}

Create a node key constraint on the label Person and properties name and age with the name constraint_name and given index provider for the accompanying range index.

CREATE CONSTRAINT constraint_name
FOR ()-[r:KNOWS]-()
REQUIRE (r.since, r.isFriend) IS RELATIONSHIP KEY

Create a relationship key constraint with the name constraint_name on the relationship type KNOWS and properties since and isFriend. If a relationship with that relationship type is created without both the since and isFriend properties, or if the combination of the two is not unique, the write operation will fail. The write operation will also fail if the since and/or isFriend properties on an existing relationship with the relationship type KNOWS is modified to violate these constraints.

Performance

Performance

Use parameters instead of literals when possible. This allows Neo4j DBMS to cache your queries instead of having to parse and build new execution plans.

Always set an upper limit for your variable length patterns. It is possible to have a query go wild and touch all nodes in a graph by mistake.

Return only the data you need. Avoid returning whole nodes and relationships; instead, pick the data you need and return only that.

Use PROFILE / EXPLAIN to analyze the performance of your queries. See Query Tuning for more information on these and other topics, such as planner hints.

Database Management

DATABASE Management

dba
`db1`
`database-name`
`database-name-123`
`database.name`
`database.name.123`

The naming rules for a database:

  • The character length of a database name must be at least 3 characters; and not more than 63 characters.

  • The first character of a database name must be an ASCII alphabetic character.

  • Subsequent characters must be ASCII alphabetic or numeric characters, dots or dashes; [a..z][0..9].-.

  • Database names are case-insensitive and normalized to lowercase.

  • Database names that begin with an underscore (_) or with the prefix system are reserved for internal use.

Database names may include dots (.) without being quoted with backticks, although this behavior is deprecated as it may introduce ambiguity when addressing composite databases. Naming a database foo.bar.baz is valid, but deprecated. `foo.bar.baz` is valid.

SHOW DATABASES

List all databases in Neo4j DBMS and information about them, returns only the default outputs (name, type, aliases, access, address, role, writer, requestedStatus, currentStatus, statusMessage, default, home, and constituents).

SHOW DATABASES YIELD *

List all databases in Neo4j DBMS and information about them.

SHOW DATABASES
YIELD name, currentStatus
WHERE name CONTAINS 'my'
  AND currentStatus = 'online'

List information about databases, filtered by name and currentStatus and further refined by conditions on these.

SHOW DATABASE `database-name` YIELD *

List information about the database database-name.

SHOW DEFAULT DATABASE

List information about the default database, for the Neo4j DBMS.

SHOW HOME DATABASE

List information about the current users home database.

DROP DATABASE `database-name` IF EXISTS

Delete the database database-name, if it exists. This command can delete both standard and composite databases.

DROP COMPOSITE DATABASE `composite-database-name`

Delete the database named composite-database-name. In case the given database name does not exist or is not composite, and error will be thrown.

DROP DATABASE `database-name` CASCADE ALIASES

Drop the database database-name and any database aliases referencing the database. This command can drop both standard and composite databases. For standard databases, the database aliases that will be dropped are any local database aliases targeting the database. For composite databases, the database aliases that will be dropped are any constituent database aliases belonging to the composite database.

CREATE DATABASE `database-name` IF NOT EXISTS

Create a standard database named database-name if it does not already exist.

CREATE OR REPLACE DATABASE `database-name`

Create a standard database named database-name. If a database with that name exists, then the existing database is deleted and a new one created.

CREATE DATABASE `topology-example` IF NOT EXISTS
TOPOLOGY 1 PRIMARY 0 SECONDARIES

Create a standard database named topology-example in a cluster environment, to use 1 primary server and 0 secondary servers.

CREATE COMPOSITE DATABASE `composite-database-name`

Create a composite database named composite-database-name.

STOP DATABASE `database-name`

Stop a database named database-name.

START DATABASE `database-name`

Start a database named database-name.

ALTER DATABASE `database-name` IF EXISTS
SET ACCESS READ ONLY

Modify a standard database named database-name to accept only read queries.

ALTER DATABASE `database-name` IF EXISTS
SET ACCESS READ WRITE

Modify a standard database named database-name to accept write and read queries.

ALTER DATABASE `topology-example`
SET TOPOLOGY 1 PRIMARY 0 SECONDARIES

Modify a standard database named topology-example in a cluster environment to use 1 primary server and 0 secondary servers.

ALTER DATABASE `topology-example`
SET TOPOLOGY 1 PRIMARY
SET ACCESS READ ONLY

Modify a standard database named topology-example in a cluster environment to use 1 primary servers and 0 secondary servers, and to only accept read queries.

ALIAS Management

SHOW ALIASES FOR DATABASE

List all database aliases in Neo4j DBMS and information about them, returns only the default outputs (name, composite, database, location, url, and user).

SHOW ALIASES `database-alias` FOR DATABASE

List the database alias named database-alias and the information about it. Returns only the default outputs (name, composite, database, location, url, and user).

SHOW ALIASES FOR DATABASE YIELD *

List all database aliases in Neo4j DBMS and information about them.

CREATE ALIAS `database-alias` IF NOT EXISTS
FOR DATABASE `database-name`

Create a local alias named database-alias for the database named database-name.

CREATE OR REPLACE ALIAS `database-alias`
FOR DATABASE `database-name`

Create or replace a local alias named database-alias for the database named database-name.

CREATE ALIAS `database-alias`
FOR DATABASE `database-name`
PROPERTIES { property = $value }

Database aliases can be given properties.

CREATE ALIAS `database-alias`
FOR DATABASE `database-name`
AT $url
USER user_name
PASSWORD $password

Create a remote alias named database-alias for the database named database-name.

CREATE ALIAS `composite-database-name`.`alias-in-composite-name`
FOR DATABASE `database-name`
AT $url
USER user_name
PASSWORD $password

Create a remote alias named alias-in-composite-name as a constituent alias in the composite database named composite-database-name for the database with name database-name.

ALTER ALIAS `database-alias` IF EXISTS
SET DATABASE TARGET `database-name`

Alter the alias named database-alias to target the database named database-name.

ALTER ALIAS `remote-database-alias` IF EXISTS
SET DATABASE
USER user_name
PASSWORD $password

Alter the remote alias named remote-database-alias, set the username (user_name) and the password.

ALTER ALIAS `database-alias`
SET DATABASE PROPERTIES { key: value }

Update the properties for the database alias named database-alias.

DROP ALIAS `database-alias` IF EXISTS FOR DATABASE

Delete the alias named database-alias.

SERVER Management

SHOW SERVERS

Display all servers running in the cluster, including servers that have yet to be enabled as well as dropped servers. Default outputs are: name, address, state, health, and hosting.

ENABLE SERVER 'serverId'

Make the server with the ID serverId an active member of the cluster.

RENAME SERVER 'oldName' TO 'newName'

Change the name of a server.

ALTER SERVER 'name' SET OPTIONS {modeConstraint: 'PRIMARY'}

Only allow the specified server to host databases in primary mode.

REALLOCATE DATABASES

Re-balance databases among the servers in the cluster.

DEALLOCATE DATABASES FROM SERVER 'name'

Remove all databases from the specified server, adding them to other servers as needed. The specified server is not allowed to host any new databases.

DROP SERVER 'name'

Remove the specified server from the cluster.

Access Control

USER Management

SHOW USERS

List all users in Neo4j DBMS, returns only the default outputs (user, roles, passwordChangeRequired, suspended, and home).

SHOW CURRENT USER

List the currently logged-in user, returns only the default outputs (user, roles, passwordChangeRequired, suspended, and home).

SHOW USERS
WHERE suspended = true

List users that are suspended.

SHOW USERS
WHERE passwordChangeRequired

List users that must change their password at the next login.

SHOW USERS WITH AUTH

List users with their auth providers. Will return one row per user per auth provider.

SHOW USERS WITH AUTH WHERE provider = 'oidc1'

List users who have the oidc1 auth provider.

DROP USER user_name

Delete the specified user.

CREATE USER user_name
SET PASSWORD $password

Create a new user and set the password. This password must be changed on the first login.

CREATE USER user_name
SET AUTH 'native' {
  SET PASSWORD $password
  SET PASSWORD CHANGE REQUIRED
}

Create a new user and set the password using the auth provider syntax. This password must be changed on the first login.

RENAME USER user_name TO other_user_name

Rename the specified user.

ALTER CURRENT USER
SET PASSWORD FROM $oldPassword TO $newPassword

Change the password of the logged-in user. The user will not be required to change this password on the next login.

ALTER USER user_name
SET PASSWORD $password
CHANGE NOT REQUIRED

Set a new password (a String) for a user. This user will not be required to change this password on the next login.

ALTER USER user_name IF EXISTS
SET PASSWORD CHANGE REQUIRED

If the specified user exists, force this user to change the password on the next login.

ALTER USER user_name
SET AUTH 'externalProviderName' {
  SET ID 'userIdForExternalProvider'
}

Add another way for the user to authenticate and authorize using the external provider externalProviderName. This provider needs to be defined in the configurations settings.

ALTER USER user_name
SET STATUS SUSPENDED

Change the status to SUSPENDED, for the specified user.

ALTER USER user_name
SET STATUS ACTIVE

Change the status to ACTIVE, for the specified user.

ALTER USER user_name
SET HOME DATABASE `database-name`

Set the home database for the specified user. The home database can either be a database or an alias.

ALTER USER user_name
REMOVE HOME DATABASE

Unset the home database for the specified user and fallback to the default database.

ROLE Management

SHOW ROLES

List all roles in the system, returns the output role.

SHOW ROLES
WHERE role CONTAINS $subString

List roles that contains a given string.

SHOW POPULATED ROLES

List all roles that are assigned to at least one user in the system.

SHOW POPULATED ROLES WITH USERS

List all roles that are assigned to at least one user in the system, and the users assigned to those roles. The returned outputs are role and member.

SHOW POPULATED ROLES WITH USERS
YIELD member, role
WHERE member = $user
RETURN role

List all roles that are assigned to a $user.

DROP ROLE role_name

Delete a role.

CREATE ROLE role_name IF NOT EXISTS

Create a role, unless it already exists.

CREATE ROLE role_name AS COPY OF other_role_name

Create a role, as a copy of the existing other_role_name.

RENAME ROLE role_name TO other_role_name

Rename a role.

GRANT ROLE role_name1, role_name2 TO user_name

Assign roles to a user.

REVOKE ROLE role_name FROM user_name

Remove the specified role from a user.

SHOW Privileges

SHOW PRIVILEGES

List all privileges in the system, and the roles that they are assigned to. Outputs returned are: access, action, resource, graph, segment, role, and immutable.

SHOW PRIVILEGES AS COMMANDS

List all privileges in the system as Cypher commands, for example GRANT ACCESS ON DATABASE * TO `admin`. Returns only the default output (command).

SHOW USER PRIVILEGES

List all privileges of the currently logged-in user, and the roles that they are assigned to. Outputs returned are: access, action, resource, graph, segment, role, immutable, and user.

SHOW USER PRIVILEGES AS COMMANDS

List all privileges of the currently logged-in user, and the roles that they are assigned to as Cypher commands, for example GRANT ACCESS ON DATABASE * TO $role. Returns only the default output (command).

SHOW USER user_name PRIVILEGES

List all privileges assigned to each of the specified users (multiple users can be specified separated by commas n1, n2, n3), and the roles that they are assigned to. Outputs returned are: access, action, resource, graph, segment, role, immutable, and user.

SHOW USER user_name PRIVILEGES AS COMMANDS YIELD *

List all privileges assigned to each of the specified users (multiple users can be specified separated by commas n1, n2, n3), as generic Cypher commands, for example GRANT ACCESS ON DATABASE * TO $role. Outputs returned are: command and immutable.

SHOW ROLE role_name PRIVILEGES

List all privileges assigned to each of the specified roles (multiple roles can be specified separated by commas r1, r2, r3). Outputs returned are: access, action, resource, graph, segment, role, and immutable.

SHOW ROLE role_name PRIVILEGES AS COMMANDS

List all privileges assigned to each of the specified roles (multiple roles can be specified separated by commas r1, r2, r3) as Cypher commands, for example GRANT ACCESS ON DATABASE * TO `admin`. Returns only the default output (command).

SHOW SUPPORTED Privileges

SHOW SUPPORTED PRIVILEGES

List all privileges that are possible to grant or deny on a server. Outputs returned are: action, qualifier, target, scope, and description.

IMMUTABLE Privileges

GRANT IMMUTABLE TRAVERSE
ON GRAPH * TO role_name

Grant immutable TRAVERSE privilege on all graphs to the specified role.

DENY IMMUTABLE START
ON DATABASE * TO role_name

Deny immutable START privilege to start all databases to the specified role.

REVOKE IMMUTABLE CREATE ROLE
ON DBMS FROM role_name

Revoke immutable CREATE ROLE privilege from the specified role. When immutable is specified in conjunction with a REVOKE command, it will act as a filter and only remove the matching immutable privileges.

Load Privileges

GRANT LOAD
ON ALL DATA
TO role_name

Grant LOAD privilege on ALL DATA to allow loading all data to the specified role.

DENY LOAD
ON CIDR "127.0.0.1/32"
TO role_name

Deny LOAD privilege on CIDR range 127.0.0.1/32 to disallow loading data from sources in that range to the specified role.

ON GRAPH

ON GRAPH Read Privileges

GRANT TRAVERSE
ON GRAPH * NODE * TO role_name

Grant TRAVERSE privilege on all graphs and all nodes to the specified role.

  • GRANT – gives privileges to roles.

  • DENY – denies privileges to roles.

REVOKE GRANT TRAVERSE
ON GRAPH * NODE * FROM role_name

To remove a granted or denied privilege, prepend the privilege query with REVOKE and replace the TO with FROM.

GRANT TRAVERSE
ON GRAPH * RELATIONSHIP * TO role_name

Grant TRAVERSE privilege on all graphs and all relationships to the specified role.

DENY READ {prop}
ON GRAPH `database-name` RELATIONSHIP rel_type TO role_name

Deny READ privilege on a specified property, on all relationships with a specified type in a specified graph, to the specified role.

REVOKE READ {prop}
ON GRAPH `database-name` FROM role_name

Revoke READ privilege on a specified property in a specified graph from the specified role.

GRANT MATCH {*}
ON HOME GRAPH ELEMENTS label_or_type TO role_name

Grant MATCH privilege on all nodes and relationships with the specified label/type, on the home graph, to the specified role. This is semantically the same as having both TRAVERSE privilege and READ {*} privilege.

GRANT READ {*}
ON GRAPH *
FOR (n) WHERE n.secret = false
TO role_name

Grant READ privilege on all graphs and all nodes with a secret property set to false to the specified role.

DENY TRAVERSE
ON GRAPH *
FOR (n:label) WHERE n.secret <> false
TO role_name

Deny TRAVERSE privilege on all graphs and all nodes with the specified label and with a secret property not set to false to the specified role.

REVOKE MATCH {*}
ON GRAPH *
FOR (n:foo_label|bar_label) WHERE n.secret IS NULL
FROM role_name

Revoke MATCH privilege on all graphs and all nodes with either foo_label or bar_label and with a secret property that is null from the specified role.

ON GRAPH Write Privileges

GRANT ALL GRAPH PRIVILEGES
ON GRAPH `database-name` TO role_name

Grant ALL GRAPH PRIVILEGES privilege on a specified graph to the specified role.

GRANT ALL ON GRAPH `database-name` TO role_name

Short form for grant ALL GRAPH PRIVILEGES privilege.

  • GRANT – gives privileges to roles.

  • DENY – denies privileges to roles.

To remove a granted or denied privilege, prepend the privilege query with REVOKE and replace the TO with FROM; (REVOKE GRANT ALL ON GRAPH `database-name FROM role_name`).

DENY CREATE
ON GRAPH * NODES node_label TO role_name

Deny CREATE privilege on all nodes with a specified label in all graphs to the specified role.

REVOKE DELETE
ON GRAPH `database-name` TO role_name

Revoke DELETE privilege on all nodes and relationships in a specified graph from the specified role.

GRANT SET LABEL node_label
ON GRAPH * TO role_name

Grant SET LABEL privilege for the specified label on all graphs to the specified role.

DENY REMOVE LABEL *
ON GRAPH `database-name` TO role_name

Deny REMOVE LABEL privilege for all labels on a specified graph to the specified role.

GRANT SET PROPERTY {prop_name}
ON GRAPH `database-name` RELATIONSHIPS rel_type TO role_name

Grant SET PROPERTY privilege on a specified property, on all relationships with a specified type in a specified graph, to the specified role.

GRANT MERGE {*}
ON GRAPH * NODES node_label TO role_name

Grant MERGE privilege on all properties, on all nodes with a specified label in all graphs, to the specified role.

REVOKE WRITE
ON GRAPH * FROM role_name

Revoke WRITE privilege on all graphs from the specified role.

ON DATABASE

ON DATABASE Privileges

GRANT ALL DATABASE PRIVILEGES
ON DATABASE * TO role_name

Grant ALL DATABASE PRIVILEGES privilege for all databases to the specified role.

  • Allows access (GRANT ACCESS).

  • Index management (GRANT INDEX MANAGEMENT).

  • Constraint management (GRANT CONSTRAINT MANAGEMENT).

  • Name management (GRANT NAME MANAGEMENT).

Note that the privileges for starting and stopping all databases, and transaction management, are not included.

GRANT ALL ON DATABASE * TO role_name

Short form for grant ALL DATABASE PRIVILEGES privilege.

  • GRANT – gives privileges to roles.

  • DENY – denies privileges to roles.

To remove a granted or denied privilege, prepend the privilege query with REVOKE and replace the TO with FROM; (REVOKE GRANT ALL ON DATABASE * FROM role_name).

REVOKE ACCESS
ON HOME DATABASE FROM role_name

Revoke ACCESS privilege to access and run queries against the home database from the specified role.

GRANT START
ON DATABASE * TO role_name

Grant START privilege to start all databases to the specified role.

DENY STOP
ON HOME DATABASE TO role_name

Deny STOP privilege to stop the home database to the specified role.

ON DATABASE - INDEX MANAGEMENT Privileges

GRANT INDEX MANAGEMENT
ON DATABASE * TO role_name

Grant INDEX MANAGEMENT privilege to create, drop, and list indexes for all database to the specified role.

  • Allow creating an index - (GRANT CREATE INDEX).

  • Allow removing an index - (GRANT DROP INDEX).

  • Allow listing an index - (GRANT SHOW INDEX).

GRANT CREATE INDEX
ON DATABASE `database-name` TO role_name

Grant CREATE INDEX privilege to create indexes on a specified database to the specified role.

GRANT DROP INDEX
ON DATABASE `database-name` TO role_name

Grant DROP INDEX privilege to drop indexes on a specified database to the specified role.

GRANT SHOW INDEX
ON DATABASE * TO role_name

Grant SHOW INDEX privilege to list indexes on all databases to the specified role.

ON DATABASE - CONSTRAINT MANAGEMENT Privileges

GRANT CONSTRAINT MANAGEMENT
ON DATABASE * TO role_name

Grant CONSTRAINT MANAGEMENT privilege to create, drop, and list constraints for all database to the specified role.

  • Allow creating a constraint - (GRANT CREATE CONSTRAINT).

  • Allow removing a constraint - (GRANT DROP CONSTRAINT).

  • Allow listing a constraint - (GRANT SHOW CONSTRAINT).

GRANT CREATE CONSTRAINT
ON DATABASE * TO role_name

Grant CREATE CONSTRAINT privilege to create constraints on all databases to the specified role.

GRANT DROP CONSTRAINT
ON DATABASE * TO role_name

Grant DROP CONSTRAINT privilege to create constraints on all databases to the specified role.

GRANT SHOW CONSTRAINT
ON DATABASE `database-name` TO role_name

Grant SHOW CONSTRAINT privilege to list constraints on a specified database to the specified role.

ON DATABASE - NAME MANAGEMENT Privileges

GRANT NAME MANAGEMENT
ON DATABASE * TO role_name

Grant NAME MANAGEMENT privilege to create new labels, new relationship types, and new property names for all databases to the specified role.

  • Allow creating a new label - (GRANT CREATE NEW LABEL).

  • Allow creating a new relationship type - (GRANT CREATE NEW TYPE).

  • Allow creating a new property name - (GRANT CREATE NEW NAME).

GRANT CREATE NEW LABEL
ON DATABASE * TO role_name

Grant CREATE NEW LABEL privilege to create new labels on all databases to the specified role.

DENY CREATE NEW TYPE
ON DATABASE * TO role_name

Deny CREATE NEW TYPE privilege to create new relationship types on all databases to the specified role.

GRANT CREATE NEW NAME
ON DATABASE * TO role_name

Grant CREATE NEW NAME privilege to create new property names on all databases to the specified role.

ON DATABASE - TRANSACTION MANAGEMENT Privileges

GRANT TRANSACTION MANAGEMENT (*)
ON DATABASE * TO role_name

Grant TRANSACTION MANAGEMENT privilege to show and terminate transactions on all users, for all databases, to the specified role.

  • Allow listing transactions - (GRANT SHOW TRANSACTION).

  • Allow terminate transactions - (GRANT TERMINATE TRANSACTION).

GRANT SHOW TRANSACTION (*)
ON DATABASE * TO role_name

Grant SHOW TRANSACTION privilege to list transactions on all users on all databases to the specified role.

GRANT SHOW TRANSACTION (user_name1, user_name2)
ON HOME DATABASE TO role_name1, role_name2

Grant SHOW TRANSACTION privilege to list transactions by the specified users on home database to the specified roles.

GRANT TERMINATE TRANSACTION (*)
ON DATABASE * TO role_name

Grant TERMINATE TRANSACTION privilege to terminate transactions on all users on all databases to the specified role.

ON DBMS

ON DBMS Privileges

GRANT ALL DBMS PRIVILEGES
ON DBMS TO role_name

Grant ALL DBMS PRIVILEGES privilege to perform management for roles, users, databases, aliases, and privileges to the specified role. Also privileges to execute procedures and user defined functions are granted.

  • Allow controlling roles - (GRANT ROLE MANAGEMENT).

  • Allow controlling users - (GRANT USER MANAGEMENT).

  • Allow controlling databases - (GRANT DATABASE MANAGEMENT).

  • Allow controlling aliases - (GRANT ALIAS MANAGEMENT).

  • Allow controlling privileges - (GRANT PRIVILEGE MANAGEMENT).

  • Allow user impersonation - (GRANT IMPERSONATE (*)).

  • Allow to execute all procedures with elevated privileges.

  • Allow to execute all user defined functions with elevated privileges.

GRANT ALL
ON DBMS TO role_name

Short form for grant ALL DBMS PRIVILEGES privilege.

  • GRANT – gives privileges to roles.

  • DENY – denies privileges to roles.

To remove a granted or denied privilege, prepend the privilege query with REVOKE and replace the TO with FROM; (REVOKE GRANT ALL ON DBMS FROM role_name).

DENY IMPERSONATE (user_name1, user_name2)
ON DBMS TO role_name

Deny IMPERSONATE privilege to impersonate the specified users (user_name1 and user_name2) to the specified role.

REVOKE IMPERSONATE (*)
ON DBMS TO role_name

Revoke IMPERSONATE privilege to impersonate all users from the specified role.

GRANT EXECUTE PROCEDURE *
ON DBMS TO role_name

Enables the specified role to execute all procedures.

GRANT EXECUTE BOOSTED PROCEDURE *
ON DBMS TO role_name

Enables the specified role to use elevated privileges when executing all procedures.

GRANT EXECUTE ADMIN PROCEDURES
ON DBMS TO role_name

Enables the specified role to execute procedures annotated with @Admin. The procedures are executed with elevated privileges.

GRANT EXECUTE FUNCTIONS *
ON DBMS TO role_name

Enables the specified role to execute all user defined functions.

GRANT EXECUTE BOOSTED FUNCTIONS *
ON DBMS TO role_name

Enables the specified role to use elevated privileges when executing all user defined functions.

GRANT SHOW SETTINGS *
ON DBMS TO role_name

Enables the specified role to view all configuration settings.

ON DBMS - ROLE MANAGEMENT Privileges

GRANT ROLE MANAGEMENT
ON DBMS TO role_name

Grant ROLE MANAGEMENT privilege to manage roles to the specified role.

  • Allow creating roles - (GRANT CREATE ROLE).

  • Allow renaming roles - (GRANT RENAME ROLE).

  • Allow deleting roles - (GRANT DROP ROLE).

  • Allow assigning (GRANT) roles to a user - (GRANT ASSIGN ROLE).

  • Allow removing (REVOKE) roles from a user - (GRANT REMOVE ROLE).

  • Allow listing roles - (GRANT SHOW ROLE).

GRANT CREATE ROLE
ON DBMS TO role_name

Grant CREATE ROLE privilege to create roles to the specified role.

GRANT RENAME ROLE
ON DBMS TO role_name

Grant RENAME ROLE privilege to rename roles to the specified role.

DENY DROP ROLE
ON DBMS TO role_name

Deny DROP ROLE privilege to delete roles to the specified role.

GRANT ASSIGN ROLE
ON DBMS TO role_name

Grant ASSIGN ROLE privilege to assign roles to users to the specified role.

DENY REMOVE ROLE
ON DBMS TO role_name

Deny REMOVE ROLE privilege to remove roles from users to the specified role.

GRANT SHOW ROLE
ON DBMS TO role_name

Grant SHOW ROLE privilege to list roles to the specified role.

ON DBMS - USER MANAGEMENT Privileges

GRANT USER MANAGEMENT
ON DBMS TO role_name

Grant USER MANAGEMENT privilege to manage users to the specified role.

  • Allow creating users - (GRANT CREATE USER).

  • Allow renaming users - (GRANT RENAME USER).

  • Allow modifying a user - (GRANT ALTER USER).

  • Allow deleting users - (GRANT DROP USER).

  • Allow listing users - (GRANT SHOW USER).

DENY CREATE USER
ON DBMS TO role_name

Deny CREATE USER privilege to create users to the specified role.

GRANT RENAME USER
ON DBMS TO role_name

Grant RENAME USER privilege to rename users to the specified role.

GRANT ALTER USER
ON DBMS TO my_role

Grant ALTER USER privilege to alter users to the specified role.

  • Allow changing a user’s password - (GRANT SET PASSWORD).

  • Allow adding or removing a user’s auth providers - (GRANT SET AUTH).

  • Allow changing a user’s home database - (GRANT SET USER HOME DATABASE).

  • Allow changing a user’s status - (GRANT USER STATUS).

DENY SET PASSWORD
ON DBMS TO role_name

Deny SET PASSWORD privilege to alter a user password to the specified role.

GRANT SET AUTH
ON DBMS TO role_name

Grant SET AUTH privilege to add/remove auth providers to the specified role.

GRANT SET USER HOME DATABASE
ON DBMS TO role_name

Grant SET USER HOME DATABASE privilege to alter the home database of users to the specified role.

GRANT SET USER STATUS
ON DBMS TO role_name

Grant SET USER STATUS privilege to alter user account status to the specified role.

GRANT DROP USER
ON DBMS TO role_name

Grant DROP USER privilege to delete users to the specified role.

DENY SHOW USER
ON DBMS TO role_name

Deny SHOW USER privilege to list users to the specified role.

ON DBMS - DATABASE MANAGEMENT Privileges

GRANT DATABASE MANAGEMENT
ON DBMS TO role_name

Grant DATABASE MANAGEMENT privilege to manage databases to the specified role.

  • Allow creating standard databases - (GRANT CREATE DATABASE).

  • Allow deleting standard databases - (GRANT DROP DATABASE).

  • Allow modifying standard databases - (GRANT ALTER DATABASE).

  • Allow managing composite databases - (GRANT COMPOSITE DATABASE MANAGEMENT).

GRANT CREATE DATABASE
ON DBMS TO role_name

Grant CREATE DATABASE privilege to create standard databases to the specified role.

GRANT DROP DATABASE
ON DBMS TO role_name

Grant DROP DATABASE privilege to delete standard databases to the specified role.

GRANT ALTER DATABASE
ON DBMS TO role_name

Grant ALTER DATABASE privilege to alter standard databases the specified role.

  • Allow modifying access mode for standard databases - (GRANT SET DATABASE ACCESS).

  • Allow modifying topology settings for standard databases.

GRANT SET DATABASE ACCESS
ON DBMS TO role_name

Grant SET DATABASE ACCESS privilege to set database access mode for standard databases to the specified role.

GRANT COMPOSITE DATABASE MANAGEMENT
ON DBMS TO role_name

Grant all privileges to manage composite databases to the specified role.

  • Allow creating composite databases - (CREATE COMPOSITE DATABASE).

  • Allow deleting composite databases - (DROP COMPOSITE DATABASE).

DENY CREATE COMPOSITE DATABASE
ON DBMS TO role_name

Denies the specified role the privilege to create composite databases.

REVOKE DROP COMPOSITE DATABASE
ON DBMS FROM role_name

Revokes the granted and denied privileges to delete composite databases from the specified role.

GRANT SERVER MANAGEMENT
ON DBMS TO role_name

Enables the specified role to show, enable, rename, alter, reallocate, deallocate, and drop servers.

DENY SHOW SERVERS
ON DBMS TO role_name

Denies the specified role the privilege to show information about the serves.

ON DBMS - ALIAS MANAGEMENT Privileges

GRANT ALIAS MANAGEMENT
ON DBMS TO role_name

Grant ALIAS MANAGEMENT privilege to manage aliases to the specified role.

  • Allow creating aliases - (GRANT CREATE ALIAS).

  • Allow deleting aliases - (GRANT DROP ALIAS).

  • Allow modifying aliases - (GRANT ALTER ALIAS).

  • Allow listing aliases - (GRANT SHOW ALIAS).

GRANT CREATE ALIAS
ON DBMS TO role_name

Grant CREATE ALIAS privilege to create aliases to the specified role.

GRANT DROP ALIAS
ON DBMS TO role_name

Grant DROP ALIAS privilege to delete aliases to the specified role.

GRANT ALTER ALIAS
ON DBMS TO role_name

Grant ALTER ALIAS privilege to alter aliases to the specified role.

GRANT SHOW ALIAS
ON DBMS TO role_name

Grant SHOW ALIAS privilege to list aliases to the specified role.

ON DBMS - ROLE MANAGEMENT Privileges

GRANT ROLE MANAGEMENT
ON DBMS TO role_name

Grant ROLE MANAGEMENT privilege to manage roles to the specified role.

  • Allow creating roles - (GRANT CREATE ROLE).

  • Allow renaming roles - (GRANT RENAME ROLE).

  • Allow deleting roles - (GRANT DROP ROLE).

  • Allow assigning (GRANT) roles to a user - (GRANT ASSIGN ROLE).

  • Allow removing (REVOKE) roles from a user - (GRANT REMOVE ROLE).

  • Allow listing roles - (GRANT SHOW ROLE).

GRANT CREATE ROLE
ON DBMS TO role_name

Grant CREATE ROLE privilege to create roles to the specified role.

GRANT RENAME ROLE
ON DBMS TO role_name

Grant RENAME ROLE privilege to rename roles to the specified role.

DENY DROP ROLE
ON DBMS TO role_name

Deny DROP ROLE privilege to delete roles to the specified role.

GRANT ASSIGN ROLE
ON DBMS TO role_name

Grant ASSIGN ROLE privilege to assign roles to users to the specified role.

DENY REMOVE ROLE
ON DBMS TO role_name

Deny REMOVE ROLE privilege to remove roles from users to the specified role.

GRANT SHOW ROLE
ON DBMS TO role_name

Grant SHOW ROLE privilege to list roles to the specified role.

ON DBMS - PRIVILEGE MANAGEMENT Privileges

GRANT PRIVILEGE MANAGEMENT
ON DBMS TO role_name

Grant PRIVILEGE MANAGEMENT privilege to manage privileges for the Neo4j DBMS to the specified role.

  • Allow assigning (GRANT|DENY) privileges for a role - (GRANT ASSIGN PRIVILEGE).

  • Allow removing (REVOKE) privileges for a role - (GRANT REMOVE PRIVILEGE).

  • Allow listing privileges - (GRANT SHOW PRIVILEGE).

GRANT ASSIGN PRIVILEGE
ON DBMS TO role_name

Grant ASSIGN PRIVILEGE privilege, allows the specified role to assign privileges for roles.

GRANT REMOVE PRIVILEGE
ON DBMS TO role_name

Grant REMOVE PRIVILEGE privilege, allows the specified role to remove privileges for roles.

GRANT SHOW PRIVILEGE
ON DBMS TO role_name

Grant SHOW PRIVILEGE privilege to list privileges to the specified role.