You are on page 1of 3

Legend RETURN ! DELETE !

RETURN * DELETE n, r
Return the value of all variables. Delete a node and a relationship.
Read
RETURN n AS columnName DETACH DELETE n
Write Use alias for result column name. Delete a node and all relationships connected to it.

General RETURN DISTINCT n MATCH (n)


Return unique rows. DETACH DELETE n
Functions Delete all nodes and relationships from the database.
ORDER BY n.property
Schema Sort the result.
FOREACH !
Performance ORDER BY n.property DESC
Sort the result in descending order. FOREACH (r IN relationships(path) |
Multidatabase SET r.marked = true)
SKIP $skipNumber Execute a mutating operation for each relationship in a
Security Skip a number of results. path.
LIMIT $limitNumber FOREACH (value IN coll |
Syntax Limit the number of results. CREATE (:Person {name: value}))
Execute a mutating operation for each element in a list.
SKIP $skipNumber LIMIT $limitNumber
Skip results at the top and limit the number of results.
Read query structure
CALL subquery !
[MATCH WHERE] RETURN count(*)
[OPTIONAL MATCH WHERE] The number of matching rows. See Aggregating functions CALL {
[WITH [ORDER BY] [SKIP] [LIMIT]] for more. MATCH (p:Person)-[:FRIEND_OF]->(other:Person) RETURN p,
RETURN [ORDER BY] [SKIP] [LIMIT] other
UNION
WITH ! MATCH (p:Child)-[:CHILD_OF]->(other:Parent) RETURN p,
MATCH ! other
MATCH (user)-[:FRIEND]-(friend) }
MATCH (n:Person)-[:KNOWS]->(m:Person) WHERE user.name = $name
WHERE n.name = 'Alice' This calls a subquery with two union parts. The result of
WITH user, count(friend) AS friends
Node patterns can contain labels and properties. WHERE friends > 10 the subquery can afterwards be post-processed.
RETURN user
MATCH (n)-->(m)
The WITH syntax is similar to RETURN. It separates query CALL procedure !
Any pattern can be used in MATCH.
parts explicitly, allowing you to declare which variables
CALL db.labels() YIELD label
MATCH (n {name: 'Alice'})-->(m) to carry over to the next part.
This shows a standalone call to the built-in procedure
Patterns with node properties.
MATCH (user)-[:FRIEND]-(friend) db.labels to list all labels used in the database. Note that
MATCH p = (n)-->(m) WITH user, count(friend) AS friends required procedure arguments are given explicitly in
Assign a path to p. ORDER BY friends DESC
brackets after the procedure name.
SKIP 1
OPTIONAL MATCH (n)-[r]->(m) LIMIT 3 CALL java.stored.procedureWithArgs
Optional pattern: nulls will be used for missing parts. RETURN user Standalone calls may omit YIELD and also provide
ORDER BY, SKIP, and LIMIT can also be used with WITH. arguments implicitly via statement parameters, e.g. a
WHERE ! standalone call requiring one argument input may be run
UNION ! by passing the parameter map {input: 'foo'}.
WHERE n.property <> $value
Use a predicate to filter. Note that WHERE is always part of MATCH (a)-[:KNOWS]->(b) CALL db.labels() YIELD label
a MATCH, OPTIONAL MATCH or WITH clause. Putting it after a RETURN b.name RETURN count(label) AS count
different clause in a query will alter what it does. UNION Calls the built-in procedure db.labels inside a larger
MATCH (a)-[:LOVES]->(b) query to count all labels used in the database. Calls
WHERE EXISTS { RETURN b.name
inside a larger query always requires passing arguments
MATCH (n)-->(m) WHERE n.age = m.age Returns the distinct union of all query results. Result
}
and naming results explicitly with YIELD.
column types and names have to match.
Use an existential subquery to filter.
MATCH (a)-[:KNOWS]->(b)
Import !
RETURN b.name
Write-only query structure UNION ALL LOAD CSV FROM
MATCH (a)-[:LOVES]->(b) 'https://neo4j.com/docs/cypher-
(CREATE | MERGE)*
RETURN b.name refcard/4.2/csv/artists.csv' AS line
[SET|DELETE|REMOVE|FOREACH]*
Returns the union of all query results, including CREATE (:Artist {name: line[1], year: toInteger(line[2])})
[RETURN [ORDER BY] [SKIP] [LIMIT]]
duplicated rows. Load data from a CSV file and create nodes.

Read-write query structure LOAD CSV WITH HEADERS FROM


MERGE ! 'https://neo4j.com/docs/cypher-refcard/4.2/csv/artists-
[MATCH WHERE] with-headers.csv' AS line
[OPTIONAL MATCH WHERE] MERGE (n:Person {name: $value}) CREATE (:Artist {name: line.Name, year:
[WITH [ORDER BY] [SKIP] [LIMIT]] ON CREATE SET n.created = timestamp() toInteger(line.Year)})
(CREATE | MERGE)* ON MATCH SET Load CSV data which has headers.
[SET|DELETE|REMOVE|FOREACH]* n.counter = coalesce(n.counter, 0) + 1,
[RETURN [ORDER BY] [SKIP] [LIMIT]] n.accessTime = timestamp() USING PERIODIC COMMIT 500
Match a pattern or create it if it does not exist. Use ON LOAD CSV WITH HEADERS FROM
CREATE and ON MATCH for conditional updates. 'https://neo4j.com/docs/cypher-refcard/4.2/csv/artists-
CREATE !
with-headers.csv' AS line
CREATE (n {name: $value}) MATCH (a:Person {name: $value1}), CREATE (:Artist {name: line.Name, year:
Create a node with the given properties. (b:Person {name: $value2}) toInteger(line.Year)})
MERGE (a)-[r:LOVES]->(b) Commit the current transaction after every 500 rows
CREATE (n $map) MERGE finds or creates a relationship between the nodes. when importing large amounts of data.
Create a node with the given properties.
MATCH (a:Person {name: $value1}) LOAD CSV FROM
UNWIND $listOfMaps AS properties MERGE 'https://neo4j.com/docs/cypher-refcard/4.2/csv/artists-
CREATE (n) SET n = properties (a)-[r:KNOWS]->(b:Person {name: $value3}) fieldterminator.csv'
Create nodes with the given properties. MERGE finds or creates paths attached to the node. AS line FIELDTERMINATOR ';'
CREATE (:Artist {name: line[1], year: toInteger(line[2])})
CREATE (n)-[r:KNOWS]->(m)
Use a different field terminator, not the default which is
Create a relationship with the given type and direction; REMOVE !
a comma (with no whitespace around it).
bind a variable to it.
REMOVE n:Person
LOAD CSV FROM
CREATE (n)-[:LOVES {since: $value}]->(m) Remove a label from n.
'https://neo4j.com/docs/cypher-
Create a relationship with the given type, direction, and refcard/4.2/csv/artists.csv' AS line
REMOVE n.property
properties. RETURN DISTINCT file()
Remove a property.
Returns the absolute path of the file that LOAD CSV is
SET ! processing, returns null if called outside of LOAD CSV
User management !
context.
SET n.property1 = $value1,
CREATE USER alice SET PASSWORD $password
n.property2 = $value2 LOAD CSV FROM
Create a new user and a password. This password must
Update or create a property. 'https://neo4j.com/docs/cypher-
be changed on the first login. refcard/4.2/csv/artists.csv' AS line
SET n = $map RETURN linenumber()
ALTER USER alice SET PASSWORD $password CHANGE NOT
Set all properties. This will remove any existing Returns the line number that LOAD CSV is currently
REQUIRED
properties. Set a new password for a user. This user will not be processing, returns null if called outside of LOAD CSV
SET n += $map required to change this password on the next login. context.
Add and update properties, while keeping existing ones.
ALTER USER alice SET STATUS SUSPENDED
SET n:Person () Change the user status to suspended. Use SET STATUS Performance !
Adds a label Person to a node. ACTIVE to reactivate the user.
Use parameters instead of literals when possible. This
ALTER CURRENT USER SET PASSWORD FROM $old TO $new
allows Cypher to re-use your queries instead of having
Database management ! Change the password of the logged-in user. The user will
to parse and build new execution plans.
CREATE OR REPLACE DATABASE myDatabase not be required to change this password on the next
Always set an upper limit for your variable length
() Create a database named myDatabase. If a database login.
patterns. It’s possible to have a query go wild and
with that name exists, then the existing database is SHOW CURRENT USER touch all nodes in a graph by mistake.
deleted and a new one created. List the currently logged-in user, their status, roles and Return only the data you need. Avoid returning whole
STOP DATABASE myDatabase whether they need to change their password. nodes and relationships — instead, pick the data you
() Stop the database myDatabase. () Status and roles are Enterprise Edition only. need and return only that.
SHOW USERS Use PROFILE / EXPLAIN to analyze the performance of
START DATABASE myDatabase
List all users in the system, their status, roles and if they your queries. See Query Tuning for more information
() Start the database myDatabase.
need to change their password. on these and other topics, such as planner hints.
SHOW DATABASES () Status and roles are Enterprise Edition only.
List all databases in the system and information about
them. DROP USER alice
(̣) Role management !
Delete the user.
SHOW DATABASE myDatabase CREATE ROLE my_role
List information about the database myDatabase. Create a role.
SHOW DEFAULT DATABASE CREATE ROLE my_second_role IF NOT EXISTS AS COPY OF
List information about the default database. my_role
Create a role named my_second_role, unless it already
DROP DATABASE myDatabase IF EXISTS
exists, as a copy of the existing my_role.
() Delete the database myDatabase, if it exists.
GRANT ROLE my_role, my_second_role TO alice
Assign roles to a user.
REVOKE ROLE my_second_role FROM alice
Remove a specified role from a user.
SHOW ROLES
List all roles 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.
DROP ROLE my_role
Delete a role.

by Neo4j, Inc..
Neo4j Cypher Refcard 4.2

Legend RETURN ! DELETE ! Operators ! Patterns ! Lists ! Functions ! Spatial functions ! Path functions !
RETURN * DELETE n, r General DISTINCT, ., [] (n:Person) ['a', 'b', 'c'] AS list coalesce(n.property, $defaultValue) point({x: $x, y: $y}) length(path)
Return the value of all variables. Delete a node and a relationship. Node with Person label. Literal lists are declared in square brackets. The first non-null expression. Returns a point in a 2D cartesian coordinate system. The number of relationships in the path.
Mathematical +, -, *, /, %, ^
Read
RETURN n AS columnName DETACH DELETE n (n:Person:Swedish) size($list) AS len, $list[0] AS value timestamp() point({latitude: $y, longitude: $x}) nodes(path)
Comparison =, <>, <, >, <=, >=, IS NULL, IS
Write Use alias for result column name. Delete a node and all relationships connected to it. Node with both Person and Swedish labels. Lists can be passed in as parameters. Milliseconds since midnight, January 1, 1970 UTC. Returns a point in a 2D geographic coordinate system, The nodes in the path as a list.
NOT NULL
with coordinates specified in decimal degrees.
General RETURN DISTINCT n MATCH (n) (n:Person {name: $value}) range($firstNum, $lastNum, $step) AS list id(nodeOrRelationship) relationships(path)
Boolean AND, OR, XOR, NOT
Return unique rows. DETACH DELETE n Node with the declared properties. range() creates a list of numbers (step is optional), other The internal id of the relationship or node. point({x: $x, y: $y, z: $z}) The relationships in the path as a list.
Functions Delete all nodes and relationships from the database. String + functions returning lists are: labels(), nodes(), Returns a point in a 3D cartesian coordinate system.
ORDER BY n.property ()-[r {name: $value}]-() toInteger($expr) [x IN nodes(path) | x.prop]
relationships().
Schema Sort the result. List +, IN, [x], [x .. y] Matches relationships with the declared properties. Converts the given input into an integer if possible; point({latitude: $y, longitude: $x, height: $z}) Extract properties from the nodes in a path.
FOREACH ! MATCH p = (a)-[:KNOWS*]->() otherwise it returns null. Returns a point in a 3D geographic coordinate system,
Performance ORDER BY n.property DESC Regular Expression =~ (n)-->(m)
FOREACH (r IN relationships(path) | RETURN relationships(p) AS r with latitude and longitude in decimal degrees, and
Sort the result in descending order. Relationship from n to m. toFloat($expr) Relationship functions !
Multidatabase SET r.marked = true) String matching STARTS WITH, ENDS WITH, The list of relationships comprising a variable length height in meters.
Converts the given input into a floating point number if type(a_relationship)
SKIP $skipNumber Execute a mutating operation for each relationship in a CONTAINS (n)--(m) path can be returned using named paths and
Security possible; otherwise it returns null. distance(point({x: $x1, y: $y1}), point({x: $x2, y: $y2})) String representation of the relationship type.
Skip a number of results. path. Relationship in any direction between n and m. relationships().
Returns a floating point number representing the linear
null ! toBoolean($expr) startNode(a_relationship)
LIMIT $limitNumber FOREACH (value IN coll | (n:Person)-->(m) RETURN matchedNode.list[0] AS value, distance between two points. The returned units will be
Syntax Converts the given input into a boolean if possible; Start node of the relationship.
Limit the number of results. CREATE (:Person {name: value})) Node n labeled Person with relationship to m. size(matchedNode.list) AS len the same as those of the point coordinates, and it will
null is used to represent missing/undefined values. Properties can be lists of strings, numbers or booleans. otherwise it returns null.
Execute a mutating operation for each element in a list. work for both 2D and 3D cartesian points. endNode(a_relationship)
SKIP $skipNumber LIMIT $limitNumber (m)<-[:KNOWS]-(n)
null is not equal to null. Not knowing two values does keys($expr) End node of the relationship.
Skip results at the top and limit the number of results. Relationship of type KNOWS from n to m. list[$idx] AS value, distance(point({latitude: $y1, longitude: $x1}),
Read query structure not imply that they are the same value. So the Returns a list of string representations for the property
CALL subquery ! list[$startIdx..$endIdx] AS slice point({latitude: $y2, longitude: $x2}))
RETURN count(*) (n)-[:KNOWS|:LOVES]->(m) id(a_relationship)
[MATCH WHERE] expression null = null yields null and not true. To List elements can be accessed with idx subscripts in names of a node, relationship, or map.
CALL { Returns the geodesic distance between two points in The internal id of the relationship.
[OPTIONAL MATCH WHERE] The number of matching rows. See Aggregating functions check if an expression is null, use IS NULL. Relationship of type KNOWS or of type LOVES from n to m.
MATCH (p:Person)-[:FRIEND_OF]->(other:Person) RETURN p, square brackets. Invalid indexes return null. Slices can properties($expr) meters. It can be used for 3D geographic points as well.
[WITH [ORDER BY] [SKIP] [LIMIT]] for more. Arithmetic expressions, comparisons and function
other (n)-[r]->(m) be retrieved with intervals from start_idx to end_idx, each Returns a map containing all the properties of a node or
RETURN [ORDER BY] [SKIP] [LIMIT]
UNION calls (except coalesce) will return null if any argument Bind the relationship to variable r. of which can be omitted or negative. Out of range INDEX !
relationship.
MATCH (p:Child)-[:CHILD_OF]->(other:Parent) RETURN p, is null. elements are ignored. Duration functions !
WITH ! CREATE INDEX FOR (p:Person) ON (p.name)
MATCH ! other (n)-[*1..5]->(m)
MATCH (user)-[:FRIEND]-(friend) An attempt to access a missing element in a list or a duration("P1Y2M10DT12H45M30.25S") Create an index on the label Person and property name.
} Variable length path of between 1 and 5 relationships UNWIND $names AS name Temporal functions !
MATCH (n:Person)-[:KNOWS]->(m:Person) WHERE user.name = $name property that doesn’t exist yields null. Returns a duration of 1 year, 2 months, 10 days, 12 hours,
This calls a subquery with two union parts. The result of from n to m. MATCH (n {name: name}) CREATE INDEX index_name FOR (p:Person) ON (p.age)
WHERE n.name = 'Alice' WITH user, count(friend) AS friends In OPTIONAL MATCH clauses, nulls will be used for missing RETURN avg(n.age) date("2018-04-05") 45 minutes and 30.25 seconds.
Node patterns can contain labels and properties. the subquery can afterwards be post-processed. Create an index on the label Person and property age with
WHERE friends > 10 parts of the pattern. (n)-[*]->(m) With UNWIND, any list can be transformed back into Returns a date parsed from a string.
duration.between($date1,$date2) the name index_name.
RETURN user Variable length path of any number of relationships from
MATCH (n)-->(m) individual rows. The example matches all names from a localtime("12:45:30.25") Returns a duration between two temporal instances.
The WITH syntax is similar to RETURN. It separates query CALL procedure ! n to m. (See Performance section.) CREATE INDEX FOR (p:Person) ON (p.surname)
Any pattern can be used in MATCH. list of names. Returns a time with no time zone.
parts explicitly, allowing you to declare which variables WITH duration("P1Y2M10DT12H45M") AS d OPTIONS {indexProvider: 'native-btree-1.0', indexConfig:
CALL db.labels() YIELD label Predicates ! (n)-[:KNOWS]->(m {property: $value})
MATCH (n {name: 'Alice'})-->(m) to carry over to the next part. MATCH (a) time("12:45:30.25+01:00") RETURN d.years, d.months, d.days, d.hours, d.minutes {`spatial.cartesian.min`: [-100.0, -100.0],
This shows a standalone call to the built-in procedure n.property <> $value A relationship of type KNOWS from a node n to a node m RETURN [(a)-->(b) WHERE b.name = 'Bob' | b.age]
Patterns with node properties. Returns a time in a specified time zone. Returns 1 year, 14 months, 10 days, 12 hours and 765 `spatial.cartesian.max`: [100.0, 100.0]}}
MATCH (user)-[:FRIEND]-(friend) db.labels to list all labels used in the database. Note that Use comparison operators. with the declared property. Pattern comprehensions may be used to do a custom Create an index on the label Person and property surname
minutes.
MATCH p = (n)-->(m) WITH user, count(friend) AS friends required procedure arguments are given explicitly in localdatetime("2018-04-05T12:34:00")
projection from a match directly into a list. with the index provider native-btree-1.0 and given
Assign a path to p. ORDER BY friends DESC exists(n.property) shortestPath((n1:Person)-[*..6]-(n2:Person))
brackets after the procedure name. Returns a datetime with no time zone. WITH duration("P1Y2M10DT12H45M") AS d
SKIP 1 Use functions. Find a single shortest path. MATCH (person) spatial.cartesian settings. The other index settings will
RETURN d.years, d.monthsOfYear, d.days, d.hours,
OPTIONAL MATCH (n)-[r]->(m) LIMIT 3 CALL java.stored.procedureWithArgs RETURN person { .name, .age} datetime("2018-04-05T12:34:00[Europe/Berlin]") d.minutesOfHour have their default values.
Optional pattern: nulls will be used for missing parts. n.number >= 1 AND n.number <= 10 allShortestPaths((n1:Person)-[*..6]->(n2:Person))
RETURN user Standalone calls may omit YIELD and also provide Map projections may be easily constructed from nodes, Returns a datetime in the specified time zone. Returns 1 year, 2 months, 10 days, 12 hours and 45
Use boolean operators to combine predicates. Find all shortest paths. CREATE INDEX FOR (p:Person) ON (p.name, p.age)
ORDER BY, SKIP, and LIMIT can also be used with WITH. arguments implicitly via statement parameters, e.g. a relationships and other map values. minutes.
datetime({epochMillis: 3360000}) Create a composite index on the label Person and the
WHERE ! standalone call requiring one argument input may be run 1 <= n.number <= 10 size((n)-->()-->())
Transforms 3360000 as a UNIX Epoch time into a normal properties name and age, throws an error if the index
date("2015-01-01") + duration("P1Y1M1D")
UNION ! by passing the parameter map {input: 'foo'}. Use chained operators to combine predicates. Count the paths matching the pattern.
WHERE n.property <> $value List predicates ! datetime. Returns a date of 2016-02-02. It is also possible to subtract already exist.
Use a predicate to filter. Note that WHERE is always part of MATCH (a)-[:KNOWS]->(b) CALL db.labels() YIELD label n:Person all(x IN coll WHERE exists(x.property)) date({year: $year, month: $month, day: $day}) durations from temporal instances. CREATE INDEX IF NOT EXISTS FOR (p:Person) ON (p.name,
a MATCH, OPTIONAL MATCH or WITH clause. Putting it after a RETURN b.name RETURN count(label) AS count Check for node labels. Labels Returns true if the predicate is true for all elements in the All of the temporal functions can also be called with a duration("PT30S") * 10
p.age)
different clause in a query will alter what it does. UNION Calls the built-in procedure db.labels inside a larger Create a composite index on the label Person and the
variable IS NULL CREATE (n:Person {name: $value}) list. map of named components. This example returns a date Returns a duration of 5 minutes. It is also possible to
MATCH (a)-[:LOVES]->(b) query to count all labels used in the database. Calls
Check if something is null. Create a node with label and property. from year, month and day components. Each function properties name and age if it does not already exist, does
WHERE EXISTS { RETURN b.name any(x IN coll WHERE exists(x.property)) divide a duration by a number.
inside a larger query always requires passing arguments nothing if it did exist.
MATCH (n)-->(m) WHERE n.age = m.age Returns the distinct union of all query results. Result supports a different set of possible components.
and naming results explicitly with YIELD. NOT exists(n.property) OR n.property = $value MERGE (n:Person {name: $value}) Returns true if the predicate is true for at least one
} column types and names have to match. Either the property does not exist or the predicate is true. Matches or creates unique node(s) with the label and element in the list. datetime({date: $date, time: $time}) SHOW INDEXES
Use an existential subquery to filter. String functions !
MATCH (a)-[:KNOWS]->(b) property. Temporal types can be created by combining other types. List all indexes.
Import ! n.property = $value none(x IN coll WHERE exists(x.property)) toString($expression)
RETURN b.name This example creates a datetime from a date and a time.
Non-existing property returns null, which is not equal to SET n:Spouse:Parent:Employee Returns true if the predicate is false for all elements in String representation of the expression. MATCH (n:Person) WHERE n.name = $value
Write-only query structure UNION ALL LOAD CSV FROM
anything. Add label(s) to a node. the list. date({date: $datetime, day: 5}) An index can be automatically used for the equality
MATCH (a)-[:LOVES]->(b) 'https://neo4j.com/docs/cypher- replace($original, $search, $replacement)
(CREATE | MERGE)* Temporal types can be created by selecting from more comparison. Note that for example toLower(n.name) =
RETURN b.name refcard/4.2/csv/artists.csv' AS line MATCH (n:Person) single(x IN coll WHERE exists(x.property)) Replace all occurrences of search with replacement. All
[SET|DELETE|REMOVE|FOREACH]* n["property"] = $value
Returns the union of all query results, including CREATE (:Artist {name: line[1], year: toInteger(line[2])}) complex types, as well as overriding individual $value will not use an index.
[RETURN [ORDER BY] [SKIP] [LIMIT]] Properties may also be accessed using a dynamically Matches nodes labeled Person. Returns true if the predicate is true for exactly one arguments must be expressions.
duplicated rows. Load data from a CSV file and create nodes. components. This example creates a date by selecting
computed property name. MATCH (n:Person) element in the list. MATCH (n:Person)
from a datetime, as well as overriding the day component. substring($original, $begin, $subLength) WHERE n.name IN [$value]
Read-write query structure LOAD CSV WITH HEADERS FROM WHERE n.name = $value
n.property STARTS WITH 'Tim' OR Get part of a string. The subLength argument is optional. An index can automatically be used for the IN list checks.
'https://neo4j.com/docs/cypher-refcard/4.2/csv/artists- Matches nodes labeled Person with the given name. WITH date("2018-04-05") AS d
MERGE ! n.property ENDS WITH 'n' OR List expressions !
[MATCH WHERE] with-headers.csv' AS line RETURN d.year, d.month, d.day, d.week, d.dayOfWeek left($original, $subLength), MATCH (n:Person)
[OPTIONAL MATCH WHERE] MERGE (n:Person {name: $value}) n.property CONTAINS 'goodie'
CREATE (:Artist {name: line.Name, year: WHERE (n:Person) size($list) right($original, $subLength)
String matching. Accessors allow extracting components of temporal WHERE n.name = $value and n.age = $value2
[WITH [ORDER BY] [SKIP] [LIMIT]] ON CREATE SET n.created = timestamp() toInteger(line.Year)}) Checks the existence of the label on the node. Number of elements in the list. types. The first part of a string. The last part of the string.
(CREATE | MERGE)* ON MATCH SET A composite index can be automatically used for equality
Load CSV data which has headers. n.property =~ 'Tim.*'
[SET|DELETE|REMOVE|FOREACH]* n.counter = coalesce(n.counter, 0) + 1, labels(n) reverse($list) trim($original), lTrim($original), comparison of both properties. Note that there needs to
[RETURN [ORDER BY] [SKIP] [LIMIT]] n.accessTime = timestamp() USING PERIODIC COMMIT 500 String regular expression matching. Labels of the node. Reverse the order of the elements in the list. Mathematical functions ! rTrim($original) be predicates on all properties of the composite index for
Match a pattern or create it if it does not exist. Use ON LOAD CSV WITH HEADERS FROM Trim all whitespace, or on the left or right side. it to be used.
(n)-[:KNOWS]->(m) REMOVE n:Person
'https://neo4j.com/docs/cypher-refcard/4.2/csv/artists- head($list), last($list), tail($list) abs($expr)
CREATE ! CREATE and ON MATCH for conditional updates. Ensure the pattern has at least one match.
with-headers.csv' AS line Remove the label from the node. head() returns the first, last() the last element of the list. The absolute value. toUpper($original), toLower($original) MATCH (n:Person)
CREATE (n {name: $value}) MATCH (a:Person {name: $value1}), CREATE (:Artist {name: line.Name, year: NOT (n)-[:KNOWS]->(m) tail() returns all but the first element. All return null for UPPERCASE and lowercase. USING INDEX n:Person(name)
Create a node with the given properties. (b:Person {name: $value2}) toInteger(line.Year)}) rand() WHERE n.name = $value
Exclude matches to (n)-[:KNOWS]->(m) from the result. Maps ! an empty list.
MERGE (a)-[r:LOVES]->(b) Commit the current transaction after every 500 rows Returns a random number in the range from 0 split($original, $delimiter) Index usage can be enforced when Cypher uses a
CREATE (n $map) MERGE finds or creates a relationship between the nodes. n.property IN [$value1, $value2] [x IN list | x.prop] (inclusive) to 1 (exclusive), [0,1). Returns a new value for Split a string into a list of strings.
when importing large amounts of data. {name: 'Alice', age: 38, suboptimal index, or more than one index should be
Create a node with the given properties. Check if an element exists in a list. address: {city: 'London', residential: true}} A list of the value of the expression for each element in each call. Also useful for selecting a subset or random
MATCH (a:Person {name: $value1}) reverse($original) used.
LOAD CSV FROM Literal maps are declared in curly braces much like the original list.
UNWIND $listOfMaps AS properties MERGE ordering. Reverse a string.
'https://neo4j.com/docs/cypher-refcard/4.2/csv/artists- DROP INDEX index_name
CREATE (n) SET n = properties (a)-[r:KNOWS]->(b:Person {name: $value3}) property maps. Lists are supported.
fieldterminator.csv' CASE ! [x IN list WHERE x.prop <> $value] round($expr) Drop the index named index_name, throws an error if the
Create nodes with the given properties. size($string)
MERGE finds or creates paths attached to the node. AS line FIELDTERMINATOR ';' WITH {person: {name: 'Anne', age: 25}} AS p A filtered list of the elements where the predicate is true. Round to the nearest integer; ceil() and floor() find the
CASE n.eyes Calculate the number of characters in the string. index does not exist.
CREATE (:Artist {name: line[1], year: toInteger(line[2])}) RETURN p.person.name
CREATE (n)-[r:KNOWS]->(m) WHEN 'blue' THEN 1 next integer up or down.
Use a different field terminator, not the default which is [x IN list WHERE x.prop <> $value | x.prop] DROP INDEX index_name IF EXISTS
Create a relationship with the given type and direction; WHEN 'brown' THEN 2 Access the property of a nested map.
REMOVE ! A list comprehension that filters a list and extracts the sqrt($expr)
a comma (with no whitespace around it). ELSE 3 Aggregating functions ! Drop the index named index_name if it exists, does nothing
bind a variable to it. MERGE (p:Person {name: $map.name}) value of the expression for each element in that list.
REMOVE n:Person END The square root. if it does not exist.
LOAD CSV FROM ON CREATE SET p = $map count(*)
CREATE (n)-[:LOVES {since: $value}]->(m) Remove a label from n. Return THEN value from the matching WHEN value. The ELSE
'https://neo4j.com/docs/cypher- Maps can be passed in as parameters and used either as reduce(s = "", x IN list | s + x.prop) sign($expr) The number of matching rows.
Create a relationship with the given type, direction, and value is optional, and substituted for null if missing. Evaluate expression for each element in the list,
REMOVE n.property refcard/4.2/csv/artists.csv' AS line a map or by accessing keys. 0 if zero, -1 if negative, 1 if positive. CONSTRAINT !
properties. RETURN DISTINCT file() accumulate the results.
count(variable)
Remove a property. CASE
Returns the absolute path of the file that LOAD CSV is MATCH (matchedNode:Person) sin($expr) The number of non-null values. CREATE CONSTRAINT ON (p:Person)
WHEN n.eyes = 'blue' THEN 1 ASSERT p.name IS UNIQUE
processing, returns null if called outside of LOAD CSV RETURN matchedNode Trigonometric functions also include cos(), tan(), cot(),
SET ! WHEN n.age < 40 THEN 2 count(DISTINCT variable)
User management ! Nodes and relationships are returned as maps of their ( ) Database privileges ! asin(), acos(), atan(), atan2(), and haversin(). All Create a unique property constraint on the label Person
context. ELSE 3 All aggregating functions also take the DISTINCT operator,
SET n.property1 = $value1, data. GRANT ACCESS ON DATABASE * TO my_role arguments for the trigonometric functions should be in and property name. If any other node with that label is
CREATE USER alice SET PASSWORD $password END which removes duplicates from the values.
n.property2 = $value2 LOAD CSV FROM radians, if not otherwise specified. updated or created with a name that already exists, the
Create a new user and a password. This password must Return THEN value from the first WHEN predicate evaluating Grant privilege to access and run queries against all
Update or create a property. 'https://neo4j.com/docs/cypher- map.name, map.age, map.children[0]
to true. Predicates are evaluated in order. databases to a role. collect(n.property) write operation will fail. This constraint will create an
be changed on the first login. refcard/4.2/csv/artists.csv' AS line Map entries can be accessed by their keys. Invalid keys degrees($expr), radians($expr), pi()
SET n = $map List from the values, ignores null. accompanying index.
ALTER USER alice SET PASSWORD $password CHANGE NOT RETURN linenumber() result in an error. GRANT START ON DATABASE * TO my_role Converts radians into degrees; use radians() for the
Set all properties. This will remove any existing Returns the line number that LOAD CSV is currently reverse, and pi() for π. sum(n.property) CREATE CONSTRAINT uniqueness ON (p:Person)
REQUIRED ( ) SHOW PRIVILEGES ! Grant privilege to start all databases to a role.
properties. processing, returns null if called outside of LOAD CSV Sum numerical values. Similar functions are avg(), min(), ASSERT p.age IS UNIQUE
Set a new password for a user. This user will not be
SHOW PRIVILEGES ( ) Graph read privileges ! GRANT STOP ON DATABASE * TO my_role log10($expr), log($expr), exp($expr), e() Create a unique property constraint on the label Person
SET n += $map required to change this password on the next login. context. max().
List all privileges in the system, and the roles that they GRANT TRAVERSE ON GRAPH * NODES * TO my_role Grant privilege to stop all databases to a role. Logarithm base 10, natural logarithm, e to the power of and property age with the name uniqueness. If any other
Add and update properties, while keeping existing ones. are assigned to. the parameter, and the value of e. percentileDisc(n.property, $percentile)
ALTER USER alice SET STATUS SUSPENDED Grant traverse privilege on all nodes and all graphs to a node with that label is updated or created with a age that
GRANT CREATE INDEX ON DATABASE foo TO my_role
SET n:Person ( ) Change the user status to suspended. Use SET STATUS Performance ! Discrete percentile. Continuous percentile is
SHOW ROLE my_role PRIVILEGES role. Grant privilege to create indexes on a specified database already exists, the write operation will fail. This
Adds a label Person to a node. ACTIVE to reactivate the user. percentileCont(). The percentile argument is from 0.0 to
List all privileges assigned to a role. to a role. ( ) Role management privileges ! constraint will create an accompanying index.
Use parameters instead of literals when possible. This DENY READ {prop} ON GRAPH foo RELATIONSHIP Type TO my_role 1.0.
ALTER CURRENT USER SET PASSWORD FROM $old TO $new Deny read privilege on a specified property, on all GRANT CREATE ROLE ON DBMS TO my_role CREATE CONSTRAINT ON (p:Person)
allows Cypher to re-use your queries instead of having SHOW ROLE my_role, my_second_role PRIVILEGES GRANT DROP INDEX ON DATABASE foo TO my_role
Database management ! Change the password of the logged-in user. The user will relationships with a specified type in a specified graph, Grant the privilege to create roles to a role. stDev(n.property) ASSERT p.surname IS UNIQUE
to parse and build new execution plans. List all privileges assigned to each of the multiple roles. Grant privilege to drop indexes on a specified database
not be required to change this password on the next Standard deviation for a sample of a population. For an OPTIONS {indexProvider: 'native-btree-1.0'}
CREATE OR REPLACE DATABASE myDatabase Always set an upper limit for your variable length to a role. to a role.
SHOW USER alice PRIVILEGES GRANT DROP ROLE ON DBMS TO my_role entire population use stDevP().
( ) Create a database named myDatabase. If a database login. Create a unique property constraint on the label Person
patterns. It’s possible to have a query go wild and List all privileges of a user, and the role that they are GRANT MATCH {*} ON DEFAULT GRAPH ELEMENTS Label TO my_role Grant the privilege to delete roles to a role.
with that name exists, then the existing database is GRANT SHOW INDEX ON DATABASE * TO my_role and property surname with the index provider native-
SHOW CURRENT USER touch all nodes in a graph by mistake. assigned to. Grant read privilege on all properties and traverse Grant privilege to show indexes on all databases to a DENY ASSIGN ROLE ON DBMS TO my_role btree-1.0 for the accompanying index.
deleted and a new one created. List the currently logged-in user, their status, roles and Return only the data you need. Avoid returning whole ( ) Database management privileges !
privilege in the default graph, to a role. Here, both role. Deny the privilege to assign roles to users to a role.
whether they need to change their password. SHOW USER PRIVILEGES CREATE CONSTRAINT ON (p:Person)
STOP DATABASE myDatabase nodes and relationships — instead, pick the data you privileges apply to all nodes and relationships with a GRANT CREATE DATABASE ON DBMS TO my_role
( ) Status and roles are Enterprise Edition only. Lists all privileges of the currently logged in user, and the DENY INDEX MANAGEMENT ON DATABASE bar TO my_role DENY REMOVE ROLE ON DBMS TO my_role Grant the privilege to create databases to a role. ASSERT exists(p.name)
( ) Stop the database myDatabase. need and return only that. specified label/type in the graph.
role that they are assigned to. Deny privilege to create and drop indexes on a specified Deny the privilege to remove roles from users to a role. ( ) Create a node property existence constraint on the
SHOW USERS Use PROFILE / EXPLAIN to analyze the performance of REVOKE DENY DROP DATABASE ON DBMS FROM my_role
START DATABASE myDatabase database to a role. label Person and property name, throws an error if the
List all users in the system, their status, roles and if they your queries. See Query Tuning for more information SHOW PRIVILEGES AS COMMANDS REVOKE DENY SHOW ROLE ON DBMS FROM my_role Revoke the denied privilege to delete databases from a
( ) Start the database myDatabase. ( ) Graph write privileges ! constraint already exists. If a node with that label is
need to change their password. on these and other topics, such as planner hints. List all privileges in the system as Cypher commands. GRANT CREATE CONSTRAINT ON DATABASE * TO my_role Revoke the denied privilege to show roles from a role. role.
SHOW DATABASES GRANT CREATE ON GRAPH * NODES Label TO my_role created without a name, or if the name property is removed
( ) Status and roles are Enterprise Edition only. Grant privilege to create constraints on all databases to a
List all databases in the system and information about Grant create privilege on all nodes with a specified label GRANT ROLE MANAGEMENT ON DBMS TO my_role DENY DATABASE MANAGEMENT ON DBMS TO my_role from an existing node with the Person label, the write
role.
them. DROP USER alice in all graphs to a role. Grant all privileges to manage roles to a role. Deny all privileges to manage database to a role. operation will fail.
( ) Role management !
Delete the user. DENY DROP CONSTRAINT ON DATABASE * TO my_role
SHOW DATABASE myDatabase DENY DELETE ON GRAPH neo4j TO my_role CREATE CONSTRAINT node_exists IF NOT EXISTS ON (p:Person)
CREATE ROLE my_role Deny privilege to drop constraints on all databases to a
Deny delete privilege on all nodes and relationships in a ( ) User management privileges ! ( ) Privilege management privileges ! ASSERT exists(p.name)
List information about the database myDatabase. Create a role. role.
specified graph to a role. ( ) If a node property existence constraint on the label
GRANT CREATE USER ON DBMS TO my_role GRANT SHOW PRIVILEGE ON DBMS TO my_role
SHOW DEFAULT DATABASE CREATE ROLE my_second_role IF NOT EXISTS AS COPY OF DENY SHOW CONSTRAINT ON DATABASE foo TO my_role Person and property name or any constraint with the name
REVOKE SET LABEL Label ON GRAPH * FROM my_role Grant the privilege to create users to a role. Grant the privilege to show privileges to a role.
List information about the default database. my_role Deny privilege to show constraints on a specified node_exists already exist then nothing happens. If no
Create a role named my_second_role, unless it already Revoke set label privilege for the specified label on all GRANT DROP USER ON DBMS TO my_role
DROP DATABASE myDatabase IF EXISTS database to a role. DENY ASSIGN PRIVILEGE ON DBMS TO my_role such constraint exists, then it will be created.
exists, as a copy of the existing my_role. graphs to a role. Grant the privilege to delete users to a role. Deny the privilege to assign privileges to roles to a role.
( ) Delete the database myDatabase, if it exists. REVOKE CONSTRAINT ON DATABASE * FROM my_role CREATE CONSTRAINT ON ()-[l:LIKED]-()
GRANT ROLE my_role, my_second_role TO alice GRANT REMOVE LABEL * ON GRAPH foo TO my_role DENY ALTER USER ON DBMS TO my_role REVOKE GRANT REMOVE PRIVILEGE ON DBMS FROM my_role ASSERT exists(l.when)
Revoke granted and denied privileges to create and drop
Assign roles to a user. Grant remove label privilege for all labels on a specified Deny the privilege to alter users to a role. Revoke the granted privilege to remove privileges from ( ) Create a relationship property existence constraint
constraints on all databases from a role.
graph to a role. roles from a role. on the type LIKED and property when. If a relationship with
REVOKE ROLE my_second_role FROM alice GRANT CREATE NEW LABELS ON DATABASE * TO my_role REVOKE SET PASSWORDS ON DBMS FROM my_role
Remove a specified role from a user. DENY SET PROPERTY {prop} ON GRAPH foo RELATIONSHIPS Type Revoke the granted and denied privileges to alter users' that type is created without a when, or if the when property
Grant privilege to create new labels on all databases to a REVOKE PRIVILEGE MANAGEMENT ON DBMS FROM my_role
TO my_role passwords from a role. is removed from an existing relationship with the LIKED
SHOW ROLES role. Revoke all granted and denied privileges for manage
Deny set property privilege on a specified property, on all type, the write operation will fail.
List all roles in the system. REVOKE GRANT SET USER STATUS ON DBMS FROM my_role privileges from a role.
relationships with a specified type in a specified graph, DENY CREATE NEW TYPES ON DATABASE foo TO my_role
Revoke the granted privilege to alter the account status CREATE CONSTRAINT relationship_exists ON ()-[l:LIKED]-()
SHOW POPULATED ROLES WITH USERS to a role. Deny privilege to create new relationship types on a ASSERT exists(l.since)
specified database to a role. of users from a role. ( ) DBMS privileges !
List all roles that are assigned to at least one user in the GRANT MERGE {*} ON GRAPH * NODES Label TO my_role ( ) Create a relationship property existence constraint
system, and the users assigned to those roles. Grant merge privilege on all properties, on all nodes with REVOKE GRANT CREATE NEW PROPERTY NAMES ON DATABASE bar REVOKE DENY SHOW USER ON DBMS FROM my_role GRANT ALL ON DBMS TO my_role on the type LIKED and property since with the name
FROM my_role Revoke the denied privilege to show users from a role. Grant privilege to perform all role management, user relationship_exists. If a relationship with that type is
DROP ROLE my_role a specified label in all graphs, to a role.
Revoke the grant privilege to create new property names management, database management and privilege created without a since, or if the since property is
Delete a role. REVOKE WRITE ON GRAPH * FROM my_role GRANT USER MANAGEMENT ON DBMS TO my_role
on a specified database from a role. management to a role. removed from an existing relationship with the LIKED
Revoke write privilege on all graphs from a role. Grant all privileges to manage users to a role.
type, the write operation will fail.
GRANT NAME MANAGEMENT ON DEFAULT DATABASE TO my_role
DENY ALL GRAPH PRIVILEGES ON GRAPH foo TO my_role
Grant privilege to create labels, relationship types, and SHOW UNIQUE CONSTRAINTS VERBOSE
Deny all graph privileges privilege on a specified graph
property names on default database to a role. List all unique constraints.
to a role.
GRANT ALL ON DATABASE baz TO my_role CREATE CONSTRAINT ON (p:Person)
Grant privilege to access, create and drop indexes and ASSERT (p.firstname, p.surname) IS NODE KEY
constraints, create new labels, types and property names ( ) Create a node key constraint on the label Person and
on a specified database to a role. properties firstname and surname. If a node with that label
is created without both firstname and surname or if the
GRANT SHOW TRANSACTION (*) ON DATABASE foo TO my_role
combination of the two is not unique, or if the firstname
Grant privilege to list transactions and queries from all
and/or surname labels on an existing node with the Person
users on a specified database to a role.
label is modified to violate these constraints, the write
DENY TERMINATE TRANSACTION (user1, user2) ON DATABASES * operation will fail.
TO my_role
CREATE CONSTRAINT node_key ON (p:Person)
Deny privilege to kill transactions and queries from
ASSERT (p.name, p.surname) IS NODE KEY
user1 and user2 on all databases to a role.
( ) Create a node key constraint on the label Person and
REVOKE GRANT TRANSACTION MANAGEMENT ON DEFAULT DATABASE properties name and surname with the name node_key. If a
FROM my_role node with that label is created without both name and
Revoke the granted privilege to list and kill transactions surname or if the combination of the two is not unique, or
and queries from all users on the default database from if the name and/or surname labels on an existing node with
a role. the Person label is modified to violate these constraints,
the write operation will fail.

CREATE CONSTRAINT node_key_with_config ON (p:Person)


ASSERT (p.name, p.age) IS NODE KEY
OPTIONS {indexConfig: {`spatial.wgs-84.min`:
[-100.0, -100.0], `spatial.wgs-84.max`: [100.0, 100.0]}}
( ) Create a node key constraint on the label Person and
properties name and age with the name
node_key_with_config and given spatial.wgs-84 settings for
the accompanying index. The other index settings will
have their default values.

DROP CONSTRAINT uniqueness


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

DROP CONSTRAINT uniqueness IF EXISTS


Drop the constraint with the name uniqueness if it exists,
does nothing if it does not exist.

by Neo4j, Inc.. ( ) Functionality available in Neo4j Enterprise Edition.


Neo4j Cypher Refcard 4.2

Legend RETURN ! DELETE ! Operators ! Patterns ! Lists ! Functions ! Spatial functions ! Path functions !
RETURN * DELETE n, r General DISTINCT, ., [] (n:Person) ['a', 'b', 'c'] AS list coalesce(n.property, $defaultValue) point({x: $x, y: $y}) length(path)
Return the value of all variables. Delete a node and a relationship. Node with Person label. Literal lists are declared in square brackets. The first non-null expression. Returns a point in a 2D cartesian coordinate system. The number of relationships in the path.
Mathematical +, -, *, /, %, ^
Read
RETURN n AS columnName DETACH DELETE n (n:Person:Swedish) size($list) AS len, $list[0] AS value timestamp() point({latitude: $y, longitude: $x}) nodes(path)
Comparison =, <>, <, >, <=, >=, IS NULL, IS
Write Use alias for result column name. Delete a node and all relationships connected to it. Node with both Person and Swedish labels. Lists can be passed in as parameters. Milliseconds since midnight, January 1, 1970 UTC. Returns a point in a 2D geographic coordinate system, The nodes in the path as a list.
NOT NULL
with coordinates specified in decimal degrees.
General RETURN DISTINCT n MATCH (n) (n:Person {name: $value}) range($firstNum, $lastNum, $step) AS list id(nodeOrRelationship) relationships(path)
Boolean AND, OR, XOR, NOT
Return unique rows. DETACH DELETE n Node with the declared properties. range() creates a list of numbers (step is optional), other The internal id of the relationship or node. point({x: $x, y: $y, z: $z}) The relationships in the path as a list.
Functions Delete all nodes and relationships from the database. String + functions returning lists are: labels(), nodes(), Returns a point in a 3D cartesian coordinate system.
ORDER BY n.property ()-[r {name: $value}]-() toInteger($expr) [x IN nodes(path) | x.prop]
relationships().
Schema Sort the result. List +, IN, [x], [x .. y] Matches relationships with the declared properties. Converts the given input into an integer if possible; point({latitude: $y, longitude: $x, height: $z}) Extract properties from the nodes in a path.
FOREACH ! MATCH p = (a)-[:KNOWS*]->() otherwise it returns null. Returns a point in a 3D geographic coordinate system,
Performance ORDER BY n.property DESC Regular Expression =~ (n)-->(m)
FOREACH (r IN relationships(path) | RETURN relationships(p) AS r with latitude and longitude in decimal degrees, and
Sort the result in descending order. Relationship from n to m. toFloat($expr) Relationship functions !
Multidatabase SET r.marked = true) String matching STARTS WITH, ENDS WITH, The list of relationships comprising a variable length height in meters.
Converts the given input into a floating point number if type(a_relationship)
SKIP $skipNumber Execute a mutating operation for each relationship in a CONTAINS (n)--(m) path can be returned using named paths and
Security possible; otherwise it returns null. distance(point({x: $x1, y: $y1}), point({x: $x2, y: $y2})) String representation of the relationship type.
Skip a number of results. path. Relationship in any direction between n and m. relationships().
Returns a floating point number representing the linear
null ! toBoolean($expr) startNode(a_relationship)
LIMIT $limitNumber FOREACH (value IN coll | (n:Person)-->(m) RETURN matchedNode.list[0] AS value, distance between two points. The returned units will be
Syntax Converts the given input into a boolean if possible; Start node of the relationship.
Limit the number of results. CREATE (:Person {name: value})) Node n labeled Person with relationship to m. size(matchedNode.list) AS len the same as those of the point coordinates, and it will
null is used to represent missing/undefined values. Properties can be lists of strings, numbers or booleans. otherwise it returns null.
Execute a mutating operation for each element in a list. work for both 2D and 3D cartesian points. endNode(a_relationship)
SKIP $skipNumber LIMIT $limitNumber (m)<-[:KNOWS]-(n)
null is not equal to null. Not knowing two values does keys($expr) End node of the relationship.
Skip results at the top and limit the number of results. Relationship of type KNOWS from n to m. list[$idx] AS value, distance(point({latitude: $y1, longitude: $x1}),
Read query structure not imply that they are the same value. So the Returns a list of string representations for the property
CALL subquery ! list[$startIdx..$endIdx] AS slice point({latitude: $y2, longitude: $x2}))
RETURN count(*) (n)-[:KNOWS|:LOVES]->(m) id(a_relationship)
[MATCH WHERE] expression null = null yields null and not true. To List elements can be accessed with idx subscripts in names of a node, relationship, or map.
CALL { Returns the geodesic distance between two points in The internal id of the relationship.
[OPTIONAL MATCH WHERE] The number of matching rows. See Aggregating functions check if an expression is null, use IS NULL. Relationship of type KNOWS or of type LOVES from n to m.
MATCH (p:Person)-[:FRIEND_OF]->(other:Person) RETURN p, square brackets. Invalid indexes return null. Slices can properties($expr) meters. It can be used for 3D geographic points as well.
[WITH [ORDER BY] [SKIP] [LIMIT]] for more. Arithmetic expressions, comparisons and function
other (n)-[r]->(m) be retrieved with intervals from start_idx to end_idx, each Returns a map containing all the properties of a node or
RETURN [ORDER BY] [SKIP] [LIMIT]
UNION calls (except coalesce) will return null if any argument Bind the relationship to variable r. of which can be omitted or negative. Out of range INDEX !
relationship.
MATCH (p:Child)-[:CHILD_OF]->(other:Parent) RETURN p, is null. elements are ignored. Duration functions !
WITH ! CREATE INDEX FOR (p:Person) ON (p.name)
MATCH ! other (n)-[*1..5]->(m)
MATCH (user)-[:FRIEND]-(friend) An attempt to access a missing element in a list or a duration("P1Y2M10DT12H45M30.25S") Create an index on the label Person and property name.
} Variable length path of between 1 and 5 relationships UNWIND $names AS name Temporal functions !
MATCH (n:Person)-[:KNOWS]->(m:Person) WHERE user.name = $name property that doesn’t exist yields null. Returns a duration of 1 year, 2 months, 10 days, 12 hours,
This calls a subquery with two union parts. The result of from n to m. MATCH (n {name: name}) CREATE INDEX index_name FOR (p:Person) ON (p.age)
WHERE n.name = 'Alice' WITH user, count(friend) AS friends In OPTIONAL MATCH clauses, nulls will be used for missing RETURN avg(n.age) date("2018-04-05") 45 minutes and 30.25 seconds.
Node patterns can contain labels and properties. the subquery can afterwards be post-processed. Create an index on the label Person and property age with
WHERE friends > 10 parts of the pattern. (n)-[*]->(m) With UNWIND, any list can be transformed back into Returns a date parsed from a string.
duration.between($date1,$date2) the name index_name.
RETURN user Variable length path of any number of relationships from
MATCH (n)-->(m) individual rows. The example matches all names from a localtime("12:45:30.25") Returns a duration between two temporal instances.
The WITH syntax is similar to RETURN. It separates query CALL procedure ! n to m. (See Performance section.) CREATE INDEX FOR (p:Person) ON (p.surname)
Any pattern can be used in MATCH. list of names. Returns a time with no time zone.
parts explicitly, allowing you to declare which variables WITH duration("P1Y2M10DT12H45M") AS d OPTIONS {indexProvider: 'native-btree-1.0', indexConfig:
CALL db.labels() YIELD label Predicates ! (n)-[:KNOWS]->(m {property: $value})
MATCH (n {name: 'Alice'})-->(m) to carry over to the next part. MATCH (a) time("12:45:30.25+01:00") RETURN d.years, d.months, d.days, d.hours, d.minutes {`spatial.cartesian.min`: [-100.0, -100.0],
This shows a standalone call to the built-in procedure n.property <> $value A relationship of type KNOWS from a node n to a node m RETURN [(a)-->(b) WHERE b.name = 'Bob' | b.age]
Patterns with node properties. Returns a time in a specified time zone. Returns 1 year, 14 months, 10 days, 12 hours and 765 `spatial.cartesian.max`: [100.0, 100.0]}}
MATCH (user)-[:FRIEND]-(friend) db.labels to list all labels used in the database. Note that Use comparison operators. with the declared property. Pattern comprehensions may be used to do a custom Create an index on the label Person and property surname
minutes.
MATCH p = (n)-->(m) WITH user, count(friend) AS friends required procedure arguments are given explicitly in localdatetime("2018-04-05T12:34:00")
projection from a match directly into a list. with the index provider native-btree-1.0 and given
Assign a path to p. ORDER BY friends DESC exists(n.property) shortestPath((n1:Person)-[*..6]-(n2:Person))
brackets after the procedure name. Returns a datetime with no time zone. WITH duration("P1Y2M10DT12H45M") AS d
SKIP 1 Use functions. Find a single shortest path. MATCH (person) spatial.cartesian settings. The other index settings will
RETURN d.years, d.monthsOfYear, d.days, d.hours,
OPTIONAL MATCH (n)-[r]->(m) LIMIT 3 CALL java.stored.procedureWithArgs RETURN person { .name, .age} datetime("2018-04-05T12:34:00[Europe/Berlin]") d.minutesOfHour have their default values.
Optional pattern: nulls will be used for missing parts. n.number >= 1 AND n.number <= 10 allShortestPaths((n1:Person)-[*..6]->(n2:Person))
RETURN user Standalone calls may omit YIELD and also provide Map projections may be easily constructed from nodes, Returns a datetime in the specified time zone. Returns 1 year, 2 months, 10 days, 12 hours and 45
Use boolean operators to combine predicates. Find all shortest paths. CREATE INDEX FOR (p:Person) ON (p.name, p.age)
ORDER BY, SKIP, and LIMIT can also be used with WITH. arguments implicitly via statement parameters, e.g. a relationships and other map values. minutes.
datetime({epochMillis: 3360000}) Create a composite index on the label Person and the
WHERE ! standalone call requiring one argument input may be run 1 <= n.number <= 10 size((n)-->()-->())
Transforms 3360000 as a UNIX Epoch time into a normal properties name and age, throws an error if the index
date("2015-01-01") + duration("P1Y1M1D")
UNION ! by passing the parameter map {input: 'foo'}. Use chained operators to combine predicates. Count the paths matching the pattern.
WHERE n.property <> $value List predicates ! datetime. Returns a date of 2016-02-02. It is also possible to subtract already exist.
Use a predicate to filter. Note that WHERE is always part of MATCH (a)-[:KNOWS]->(b) CALL db.labels() YIELD label n:Person all(x IN coll WHERE exists(x.property)) date({year: $year, month: $month, day: $day}) durations from temporal instances. CREATE INDEX IF NOT EXISTS FOR (p:Person) ON (p.name,
a MATCH, OPTIONAL MATCH or WITH clause. Putting it after a RETURN b.name RETURN count(label) AS count Check for node labels. Labels Returns true if the predicate is true for all elements in the All of the temporal functions can also be called with a duration("PT30S") * 10
p.age)
different clause in a query will alter what it does. UNION Calls the built-in procedure db.labels inside a larger Create a composite index on the label Person and the
variable IS NULL CREATE (n:Person {name: $value}) list. map of named components. This example returns a date Returns a duration of 5 minutes. It is also possible to
MATCH (a)-[:LOVES]->(b) query to count all labels used in the database. Calls
Check if something is null. Create a node with label and property. from year, month and day components. Each function properties name and age if it does not already exist, does
WHERE EXISTS { RETURN b.name any(x IN coll WHERE exists(x.property)) divide a duration by a number.
inside a larger query always requires passing arguments nothing if it did exist.
MATCH (n)-->(m) WHERE n.age = m.age Returns the distinct union of all query results. Result supports a different set of possible components.
and naming results explicitly with YIELD. NOT exists(n.property) OR n.property = $value MERGE (n:Person {name: $value}) Returns true if the predicate is true for at least one
} column types and names have to match. Either the property does not exist or the predicate is true. Matches or creates unique node(s) with the label and element in the list. datetime({date: $date, time: $time}) SHOW INDEXES
Use an existential subquery to filter. String functions !
MATCH (a)-[:KNOWS]->(b) property. Temporal types can be created by combining other types. List all indexes.
Import ! n.property = $value none(x IN coll WHERE exists(x.property)) toString($expression)
RETURN b.name This example creates a datetime from a date and a time.
Non-existing property returns null, which is not equal to SET n:Spouse:Parent:Employee Returns true if the predicate is false for all elements in String representation of the expression. MATCH (n:Person) WHERE n.name = $value
Write-only query structure UNION ALL LOAD CSV FROM
anything. Add label(s) to a node. the list. date({date: $datetime, day: 5}) An index can be automatically used for the equality
MATCH (a)-[:LOVES]->(b) 'https://neo4j.com/docs/cypher- replace($original, $search, $replacement)
(CREATE | MERGE)* Temporal types can be created by selecting from more comparison. Note that for example toLower(n.name) =
RETURN b.name refcard/4.2/csv/artists.csv' AS line MATCH (n:Person) single(x IN coll WHERE exists(x.property)) Replace all occurrences of search with replacement. All
[SET|DELETE|REMOVE|FOREACH]* n["property"] = $value
Returns the union of all query results, including CREATE (:Artist {name: line[1], year: toInteger(line[2])}) complex types, as well as overriding individual $value will not use an index.
[RETURN [ORDER BY] [SKIP] [LIMIT]] Properties may also be accessed using a dynamically Matches nodes labeled Person. Returns true if the predicate is true for exactly one arguments must be expressions.
duplicated rows. Load data from a CSV file and create nodes. components. This example creates a date by selecting
computed property name. MATCH (n:Person) element in the list. MATCH (n:Person)
from a datetime, as well as overriding the day component. substring($original, $begin, $subLength) WHERE n.name IN [$value]
Read-write query structure LOAD CSV WITH HEADERS FROM WHERE n.name = $value
n.property STARTS WITH 'Tim' OR Get part of a string. The subLength argument is optional. An index can automatically be used for the IN list checks.
'https://neo4j.com/docs/cypher-refcard/4.2/csv/artists- Matches nodes labeled Person with the given name. WITH date("2018-04-05") AS d
MERGE ! n.property ENDS WITH 'n' OR List expressions !
[MATCH WHERE] with-headers.csv' AS line RETURN d.year, d.month, d.day, d.week, d.dayOfWeek left($original, $subLength), MATCH (n:Person)
[OPTIONAL MATCH WHERE] MERGE (n:Person {name: $value}) n.property CONTAINS 'goodie'
CREATE (:Artist {name: line.Name, year: WHERE (n:Person) size($list) right($original, $subLength)
String matching. Accessors allow extracting components of temporal WHERE n.name = $value and n.age = $value2
[WITH [ORDER BY] [SKIP] [LIMIT]] ON CREATE SET n.created = timestamp() toInteger(line.Year)}) Checks the existence of the label on the node. Number of elements in the list. types. The first part of a string. The last part of the string.
(CREATE | MERGE)* ON MATCH SET A composite index can be automatically used for equality
Load CSV data which has headers. n.property =~ 'Tim.*'
[SET|DELETE|REMOVE|FOREACH]* n.counter = coalesce(n.counter, 0) + 1, labels(n) reverse($list) trim($original), lTrim($original), comparison of both properties. Note that there needs to
[RETURN [ORDER BY] [SKIP] [LIMIT]] n.accessTime = timestamp() USING PERIODIC COMMIT 500 String regular expression matching. Labels of the node. Reverse the order of the elements in the list. Mathematical functions ! rTrim($original) be predicates on all properties of the composite index for
Match a pattern or create it if it does not exist. Use ON LOAD CSV WITH HEADERS FROM Trim all whitespace, or on the left or right side. it to be used.
(n)-[:KNOWS]->(m) REMOVE n:Person
'https://neo4j.com/docs/cypher-refcard/4.2/csv/artists- head($list), last($list), tail($list) abs($expr)
CREATE ! CREATE and ON MATCH for conditional updates. Ensure the pattern has at least one match.
with-headers.csv' AS line Remove the label from the node. head() returns the first, last() the last element of the list. The absolute value. toUpper($original), toLower($original) MATCH (n:Person)
CREATE (n {name: $value}) MATCH (a:Person {name: $value1}), CREATE (:Artist {name: line.Name, year: NOT (n)-[:KNOWS]->(m) tail() returns all but the first element. All return null for UPPERCASE and lowercase. USING INDEX n:Person(name)
Create a node with the given properties. (b:Person {name: $value2}) toInteger(line.Year)}) rand() WHERE n.name = $value
Exclude matches to (n)-[:KNOWS]->(m) from the result. Maps ! an empty list.
MERGE (a)-[r:LOVES]->(b) Commit the current transaction after every 500 rows Returns a random number in the range from 0 split($original, $delimiter) Index usage can be enforced when Cypher uses a
CREATE (n $map) MERGE finds or creates a relationship between the nodes. n.property IN [$value1, $value2] [x IN list | x.prop] (inclusive) to 1 (exclusive), [0,1). Returns a new value for Split a string into a list of strings.
when importing large amounts of data. {name: 'Alice', age: 38, suboptimal index, or more than one index should be
Create a node with the given properties. Check if an element exists in a list. address: {city: 'London', residential: true}} A list of the value of the expression for each element in each call. Also useful for selecting a subset or random
MATCH (a:Person {name: $value1}) reverse($original) used.
LOAD CSV FROM Literal maps are declared in curly braces much like the original list.
UNWIND $listOfMaps AS properties MERGE ordering. Reverse a string.
'https://neo4j.com/docs/cypher-refcard/4.2/csv/artists- DROP INDEX index_name
CREATE (n) SET n = properties (a)-[r:KNOWS]->(b:Person {name: $value3}) property maps. Lists are supported.
fieldterminator.csv' CASE ! [x IN list WHERE x.prop <> $value] round($expr) Drop the index named index_name, throws an error if the
Create nodes with the given properties. size($string)
MERGE finds or creates paths attached to the node. AS line FIELDTERMINATOR ';' WITH {person: {name: 'Anne', age: 25}} AS p A filtered list of the elements where the predicate is true. Round to the nearest integer; ceil() and floor() find the
CASE n.eyes Calculate the number of characters in the string. index does not exist.
CREATE (:Artist {name: line[1], year: toInteger(line[2])}) RETURN p.person.name
CREATE (n)-[r:KNOWS]->(m) WHEN 'blue' THEN 1 next integer up or down.
Use a different field terminator, not the default which is [x IN list WHERE x.prop <> $value | x.prop] DROP INDEX index_name IF EXISTS
Create a relationship with the given type and direction; WHEN 'brown' THEN 2 Access the property of a nested map.
REMOVE ! A list comprehension that filters a list and extracts the sqrt($expr)
a comma (with no whitespace around it). ELSE 3 Aggregating functions ! Drop the index named index_name if it exists, does nothing
bind a variable to it. MERGE (p:Person {name: $map.name}) value of the expression for each element in that list.
REMOVE n:Person END The square root. if it does not exist.
LOAD CSV FROM ON CREATE SET p = $map count(*)
CREATE (n)-[:LOVES {since: $value}]->(m) Remove a label from n. Return THEN value from the matching WHEN value. The ELSE
'https://neo4j.com/docs/cypher- Maps can be passed in as parameters and used either as reduce(s = "", x IN list | s + x.prop) sign($expr) The number of matching rows.
Create a relationship with the given type, direction, and value is optional, and substituted for null if missing. Evaluate expression for each element in the list,
REMOVE n.property refcard/4.2/csv/artists.csv' AS line a map or by accessing keys. 0 if zero, -1 if negative, 1 if positive. CONSTRAINT !
properties. RETURN DISTINCT file() accumulate the results.
count(variable)
Remove a property. CASE
Returns the absolute path of the file that LOAD CSV is MATCH (matchedNode:Person) sin($expr) The number of non-null values. CREATE CONSTRAINT ON (p:Person)
WHEN n.eyes = 'blue' THEN 1 ASSERT p.name IS UNIQUE
processing, returns null if called outside of LOAD CSV RETURN matchedNode Trigonometric functions also include cos(), tan(), cot(),
SET ! WHEN n.age < 40 THEN 2 count(DISTINCT variable)
User management ! Nodes and relationships are returned as maps of their ( ) Database privileges ! asin(), acos(), atan(), atan2(), and haversin(). All Create a unique property constraint on the label Person
context. ELSE 3 All aggregating functions also take the DISTINCT operator,
SET n.property1 = $value1, data. GRANT ACCESS ON DATABASE * TO my_role arguments for the trigonometric functions should be in and property name. If any other node with that label is
CREATE USER alice SET PASSWORD $password END which removes duplicates from the values.
n.property2 = $value2 LOAD CSV FROM radians, if not otherwise specified. updated or created with a name that already exists, the
Create a new user and a password. This password must Return THEN value from the first WHEN predicate evaluating Grant privilege to access and run queries against all
Update or create a property. 'https://neo4j.com/docs/cypher- map.name, map.age, map.children[0]
to true. Predicates are evaluated in order. databases to a role. collect(n.property) write operation will fail. This constraint will create an
be changed on the first login. refcard/4.2/csv/artists.csv' AS line Map entries can be accessed by their keys. Invalid keys degrees($expr), radians($expr), pi()
SET n = $map List from the values, ignores null. accompanying index.
ALTER USER alice SET PASSWORD $password CHANGE NOT RETURN linenumber() result in an error. GRANT START ON DATABASE * TO my_role Converts radians into degrees; use radians() for the
Set all properties. This will remove any existing Returns the line number that LOAD CSV is currently reverse, and pi() for π. sum(n.property) CREATE CONSTRAINT uniqueness ON (p:Person)
REQUIRED ( ) SHOW PRIVILEGES ! Grant privilege to start all databases to a role.
properties. processing, returns null if called outside of LOAD CSV Sum numerical values. Similar functions are avg(), min(), ASSERT p.age IS UNIQUE
Set a new password for a user. This user will not be
SHOW PRIVILEGES ( ) Graph read privileges ! GRANT STOP ON DATABASE * TO my_role log10($expr), log($expr), exp($expr), e() Create a unique property constraint on the label Person
SET n += $map required to change this password on the next login. context. max().
List all privileges in the system, and the roles that they GRANT TRAVERSE ON GRAPH * NODES * TO my_role Grant privilege to stop all databases to a role. Logarithm base 10, natural logarithm, e to the power of and property age with the name uniqueness. If any other
Add and update properties, while keeping existing ones. are assigned to. the parameter, and the value of e. percentileDisc(n.property, $percentile)
ALTER USER alice SET STATUS SUSPENDED Grant traverse privilege on all nodes and all graphs to a node with that label is updated or created with a age that
GRANT CREATE INDEX ON DATABASE foo TO my_role
SET n:Person ( ) Change the user status to suspended. Use SET STATUS Performance ! Discrete percentile. Continuous percentile is
SHOW ROLE my_role PRIVILEGES role. Grant privilege to create indexes on a specified database already exists, the write operation will fail. This
Adds a label Person to a node. ACTIVE to reactivate the user. percentileCont(). The percentile argument is from 0.0 to
List all privileges assigned to a role. to a role. ( ) Role management privileges ! constraint will create an accompanying index.
Use parameters instead of literals when possible. This DENY READ {prop} ON GRAPH foo RELATIONSHIP Type TO my_role 1.0.
ALTER CURRENT USER SET PASSWORD FROM $old TO $new Deny read privilege on a specified property, on all GRANT CREATE ROLE ON DBMS TO my_role CREATE CONSTRAINT ON (p:Person)
allows Cypher to re-use your queries instead of having SHOW ROLE my_role, my_second_role PRIVILEGES GRANT DROP INDEX ON DATABASE foo TO my_role
Database management ! Change the password of the logged-in user. The user will relationships with a specified type in a specified graph, Grant the privilege to create roles to a role. stDev(n.property) ASSERT p.surname IS UNIQUE
to parse and build new execution plans. List all privileges assigned to each of the multiple roles. Grant privilege to drop indexes on a specified database
not be required to change this password on the next Standard deviation for a sample of a population. For an OPTIONS {indexProvider: 'native-btree-1.0'}
CREATE OR REPLACE DATABASE myDatabase Always set an upper limit for your variable length to a role. to a role.
SHOW USER alice PRIVILEGES GRANT DROP ROLE ON DBMS TO my_role entire population use stDevP().
( ) Create a database named myDatabase. If a database login. Create a unique property constraint on the label Person
patterns. It’s possible to have a query go wild and List all privileges of a user, and the role that they are GRANT MATCH {*} ON DEFAULT GRAPH ELEMENTS Label TO my_role Grant the privilege to delete roles to a role.
with that name exists, then the existing database is GRANT SHOW INDEX ON DATABASE * TO my_role and property surname with the index provider native-
SHOW CURRENT USER touch all nodes in a graph by mistake. assigned to. Grant read privilege on all properties and traverse Grant privilege to show indexes on all databases to a DENY ASSIGN ROLE ON DBMS TO my_role btree-1.0 for the accompanying index.
deleted and a new one created. List the currently logged-in user, their status, roles and Return only the data you need. Avoid returning whole ( ) Database management privileges !
privilege in the default graph, to a role. Here, both role. Deny the privilege to assign roles to users to a role.
whether they need to change their password. SHOW USER PRIVILEGES CREATE CONSTRAINT ON (p:Person)
STOP DATABASE myDatabase nodes and relationships — instead, pick the data you privileges apply to all nodes and relationships with a GRANT CREATE DATABASE ON DBMS TO my_role
( ) Status and roles are Enterprise Edition only. Lists all privileges of the currently logged in user, and the DENY INDEX MANAGEMENT ON DATABASE bar TO my_role DENY REMOVE ROLE ON DBMS TO my_role Grant the privilege to create databases to a role. ASSERT exists(p.name)
( ) Stop the database myDatabase. need and return only that. specified label/type in the graph.
role that they are assigned to. Deny privilege to create and drop indexes on a specified Deny the privilege to remove roles from users to a role. ( ) Create a node property existence constraint on the
SHOW USERS Use PROFILE / EXPLAIN to analyze the performance of REVOKE DENY DROP DATABASE ON DBMS FROM my_role
START DATABASE myDatabase database to a role. label Person and property name, throws an error if the
List all users in the system, their status, roles and if they your queries. See Query Tuning for more information SHOW PRIVILEGES AS COMMANDS REVOKE DENY SHOW ROLE ON DBMS FROM my_role Revoke the denied privilege to delete databases from a
( ) Start the database myDatabase. ( ) Graph write privileges ! constraint already exists. If a node with that label is
need to change their password. on these and other topics, such as planner hints. List all privileges in the system as Cypher commands. GRANT CREATE CONSTRAINT ON DATABASE * TO my_role Revoke the denied privilege to show roles from a role. role.
SHOW DATABASES GRANT CREATE ON GRAPH * NODES Label TO my_role created without a name, or if the name property is removed
( ) Status and roles are Enterprise Edition only. Grant privilege to create constraints on all databases to a
List all databases in the system and information about Grant create privilege on all nodes with a specified label GRANT ROLE MANAGEMENT ON DBMS TO my_role DENY DATABASE MANAGEMENT ON DBMS TO my_role from an existing node with the Person label, the write
role.
them. DROP USER alice in all graphs to a role. Grant all privileges to manage roles to a role. Deny all privileges to manage database to a role. operation will fail.
( ) Role management !
Delete the user. DENY DROP CONSTRAINT ON DATABASE * TO my_role
SHOW DATABASE myDatabase DENY DELETE ON GRAPH neo4j TO my_role CREATE CONSTRAINT node_exists IF NOT EXISTS ON (p:Person)
CREATE ROLE my_role Deny privilege to drop constraints on all databases to a
Deny delete privilege on all nodes and relationships in a ( ) User management privileges ! ( ) Privilege management privileges ! ASSERT exists(p.name)
List information about the database myDatabase. Create a role. role.
specified graph to a role. ( ) If a node property existence constraint on the label
GRANT CREATE USER ON DBMS TO my_role GRANT SHOW PRIVILEGE ON DBMS TO my_role
SHOW DEFAULT DATABASE CREATE ROLE my_second_role IF NOT EXISTS AS COPY OF DENY SHOW CONSTRAINT ON DATABASE foo TO my_role Person and property name or any constraint with the name
REVOKE SET LABEL Label ON GRAPH * FROM my_role Grant the privilege to create users to a role. Grant the privilege to show privileges to a role.
List information about the default database. my_role Deny privilege to show constraints on a specified node_exists already exist then nothing happens. If no
Create a role named my_second_role, unless it already Revoke set label privilege for the specified label on all GRANT DROP USER ON DBMS TO my_role
DROP DATABASE myDatabase IF EXISTS database to a role. DENY ASSIGN PRIVILEGE ON DBMS TO my_role such constraint exists, then it will be created.
exists, as a copy of the existing my_role. graphs to a role. Grant the privilege to delete users to a role. Deny the privilege to assign privileges to roles to a role.
( ) Delete the database myDatabase, if it exists. REVOKE CONSTRAINT ON DATABASE * FROM my_role CREATE CONSTRAINT ON ()-[l:LIKED]-()
GRANT ROLE my_role, my_second_role TO alice GRANT REMOVE LABEL * ON GRAPH foo TO my_role DENY ALTER USER ON DBMS TO my_role REVOKE GRANT REMOVE PRIVILEGE ON DBMS FROM my_role ASSERT exists(l.when)
Revoke granted and denied privileges to create and drop
Assign roles to a user. Grant remove label privilege for all labels on a specified Deny the privilege to alter users to a role. Revoke the granted privilege to remove privileges from ( ) Create a relationship property existence constraint
constraints on all databases from a role.
graph to a role. roles from a role. on the type LIKED and property when. If a relationship with
REVOKE ROLE my_second_role FROM alice GRANT CREATE NEW LABELS ON DATABASE * TO my_role REVOKE SET PASSWORDS ON DBMS FROM my_role
Remove a specified role from a user. DENY SET PROPERTY {prop} ON GRAPH foo RELATIONSHIPS Type Revoke the granted and denied privileges to alter users' that type is created without a when, or if the when property
Grant privilege to create new labels on all databases to a REVOKE PRIVILEGE MANAGEMENT ON DBMS FROM my_role
TO my_role passwords from a role. is removed from an existing relationship with the LIKED
SHOW ROLES role. Revoke all granted and denied privileges for manage
Deny set property privilege on a specified property, on all type, the write operation will fail.
List all roles in the system. REVOKE GRANT SET USER STATUS ON DBMS FROM my_role privileges from a role.
relationships with a specified type in a specified graph, DENY CREATE NEW TYPES ON DATABASE foo TO my_role
Revoke the granted privilege to alter the account status CREATE CONSTRAINT relationship_exists ON ()-[l:LIKED]-()
SHOW POPULATED ROLES WITH USERS to a role. Deny privilege to create new relationship types on a ASSERT exists(l.since)
specified database to a role. of users from a role. ( ) DBMS privileges !
List all roles that are assigned to at least one user in the GRANT MERGE {*} ON GRAPH * NODES Label TO my_role ( ) Create a relationship property existence constraint
system, and the users assigned to those roles. Grant merge privilege on all properties, on all nodes with REVOKE GRANT CREATE NEW PROPERTY NAMES ON DATABASE bar REVOKE DENY SHOW USER ON DBMS FROM my_role GRANT ALL ON DBMS TO my_role on the type LIKED and property since with the name
FROM my_role Revoke the denied privilege to show users from a role. Grant privilege to perform all role management, user relationship_exists. If a relationship with that type is
DROP ROLE my_role a specified label in all graphs, to a role.
Revoke the grant privilege to create new property names management, database management and privilege created without a since, or if the since property is
Delete a role. REVOKE WRITE ON GRAPH * FROM my_role GRANT USER MANAGEMENT ON DBMS TO my_role
on a specified database from a role. management to a role. removed from an existing relationship with the LIKED
Revoke write privilege on all graphs from a role. Grant all privileges to manage users to a role.
type, the write operation will fail.
GRANT NAME MANAGEMENT ON DEFAULT DATABASE TO my_role
DENY ALL GRAPH PRIVILEGES ON GRAPH foo TO my_role
Grant privilege to create labels, relationship types, and SHOW UNIQUE CONSTRAINTS VERBOSE
Deny all graph privileges privilege on a specified graph
property names on default database to a role. List all unique constraints.
to a role.
GRANT ALL ON DATABASE baz TO my_role CREATE CONSTRAINT ON (p:Person)
Grant privilege to access, create and drop indexes and ASSERT (p.firstname, p.surname) IS NODE KEY
constraints, create new labels, types and property names ( ) Create a node key constraint on the label Person and
on a specified database to a role. properties firstname and surname. If a node with that label
is created without both firstname and surname or if the
GRANT SHOW TRANSACTION (*) ON DATABASE foo TO my_role
combination of the two is not unique, or if the firstname
Grant privilege to list transactions and queries from all
and/or surname labels on an existing node with the Person
users on a specified database to a role.
label is modified to violate these constraints, the write
DENY TERMINATE TRANSACTION (user1, user2) ON DATABASES * operation will fail.
TO my_role
CREATE CONSTRAINT node_key ON (p:Person)
Deny privilege to kill transactions and queries from
ASSERT (p.name, p.surname) IS NODE KEY
user1 and user2 on all databases to a role.
( ) Create a node key constraint on the label Person and
REVOKE GRANT TRANSACTION MANAGEMENT ON DEFAULT DATABASE properties name and surname with the name node_key. If a
FROM my_role node with that label is created without both name and
Revoke the granted privilege to list and kill transactions surname or if the combination of the two is not unique, or
and queries from all users on the default database from if the name and/or surname labels on an existing node with
a role. the Person label is modified to violate these constraints,
the write operation will fail.

CREATE CONSTRAINT node_key_with_config ON (p:Person)


ASSERT (p.name, p.age) IS NODE KEY
OPTIONS {indexConfig: {`spatial.wgs-84.min`:
[-100.0, -100.0], `spatial.wgs-84.max`: [100.0, 100.0]}}
( ) Create a node key constraint on the label Person and
properties name and age with the name
node_key_with_config and given spatial.wgs-84 settings for
the accompanying index. The other index settings will
have their default values.

DROP CONSTRAINT uniqueness


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

DROP CONSTRAINT uniqueness IF EXISTS


Drop the constraint with the name uniqueness if it exists,
does nothing if it does not exist.

by Neo4j, Inc.. ( ) Functionality available in Neo4j Enterprise Edition.

You might also like