Queries

For detailed information on Cypher administrative commands, see Cypher Manual → Database management.

All commands and example queries in this section are run in the Neo4j Cypher Shell command-line interface (CLI).

Note that the cypher-shell queries are not case-sensitive, but must end with a semicolon.

Show the status of a specific database

Example 1. SHOW DATABASE
neo4j@system> SHOW DATABASE neo4j;

In standalone mode:

+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| name    | type       | aliases | access       | address          | role      | writer | requestedStatus | currentStatus | statusMessage | default | home  | constituents |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| "neo4j" | "standard" | []      | "read-write" | "localhost:7687" | "primary" | TRUE   | "online"        | "online"      | ""            | TRUE    | TRUE  | []           |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

1 row available after 100 ms, consumed after another 6 ms

Or in a cluster:

+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| name    | type       | aliases | access       | address          | role      | writer | requestedStatus | currentStatus | statusMessage | default   | home  | constituents |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| "neo4j" | "standard" | []      | "read-write" | "localhost:7687" | "primary" | TRUE   | "online"        | "online"      | ""            | TRUE      | TRUE  | []           |
| "neo4j" | "standard" | []      | "read-write" | "localhost:7688" | "primary" | FALSE  | "online"        | "online"      | ""            | TRUE      | TRUE  | []           |
| "neo4j" | "standard" | []      | "read-write" | "localhost:7689" | "primary" | FALSE  | "online"        | "online"      | ""            | TRUE      | TRUE  | []           |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

3 row available after 100 ms, consumed after another 6 ms

Show the status of all databases

Example 2. SHOW DATABASES
neo4j@system> SHOW DATABASES;

In standalone mode:

+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| name     | type       | aliases | access       | address          | role      | writer | requestedStatus | currentStatus | statusMessage | default | home  | constituents |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| "neo4j"  | "standard" | []      | "read-write" | "localhost:7687" | "primary" | TRUE   | "online"        | "online"      | ""            | TRUE    | TRUE  | []           |
| "system" | "system"   | []      | "read-write" | "localhost:7687" | "primary" | TRUE   | "online"        | "online"      | ""            | FALSE   | FALSE | []           |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

2 rows available after 5 ms, consumed after another 1 ms

Or in a cluster:

+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| name     | type       | aliases | access       | address          | role      | writer | requestedStatus | currentStatus | statusMessage | default   | home  | constituents |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| "neo4j"  | "standard" | []      | "read-write" | "localhost:7687" | "primary" | TRUE   | "online"        | "online"      | ""            | TRUE      | TRUE  | []           |
| "neo4j"  | "standard" | []      | "read-write" | "localhost:7688" | "primary" | FALSE  | "online"        | "online"      | ""            | TRUE      | TRUE  | []           |
| "neo4j"  | "standard" | []      | "read-write" | "localhost:7689" | "primary" | FALSE  | "online"        | "online"      | ""            | TRUE      | TRUE  | []           |
| "system" | "system"   | []      | "read-write" | "localhost:7687" | "primary" | FALSE  | "online"        | "online"      | ""            | FALSE     | FALSE | []           |
| "system" | "system"   | []      | "read-write" | "localhost:7688" | "primary" | TRUE   | "online"        | "online"      | ""            | FALSE     | FALSE | []           |
| "system" | "system"   | []      | "read-write" | "localhost:7689" | "primary" | FALSE  | "online"        | "online"      | ""            | FALSE     | FALSE | []           |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

6 rows available after 5 ms, consumed after another 1 ms

Switching between online and offline states is achieved using the START DATABASE and STOP DATABASE commands.

Show the status of the default database

The config setting initial.dbms.default_database defines which database is created and started by default when Neo4j starts. The default value of this setting is neo4j.

Example 3. SHOW DEFAULT DATABASE
neo4j@system> SHOW DEFAULT DATABASE;

In standalone mode:

+--------------------------------------------------------------------------------------------------------------------------------------------------------+
| name    | type       | aliases | access       | address          | role      | writer | requestedStatus | currentStatus | statusMessage | constituents |
+--------------------------------------------------------------------------------------------------------------------------------------------------------+
| "neo4j" | "standard" | []      | "read-write" | "localhost:7687" | "primary" | TRUE   | "online"        | "online"      | ""            | []           |
+--------------------------------------------------------------------------------------------------------------------------------------------------------+

1 row available after 57 ms, consumed after another 2 ms

Or in a cluster:

+----------------------------------------------------------------------------------------------------------------------------------------------------------+
| name    | type       | aliases | access       | address          | role      | writer | requestedStatus | currentStatus | statusMessage   | constituents |
+----------------------------------------------------------------------------------------------------------------------------------------------------------+
| "neo4j" | "standard" | []      | "read-write" | "localhost:7687" | "primary" | FALSE  | "online"        | "online"      | ""              | []           |
| "neo4j" | "standard" | []      | "read-write" | "localhost:7688" | "primary" | TRUE   | "online"        | "online"      | ""              | []           |
| "neo4j" | "standard" | []      | "read-write" | "localhost:7689" | "primary" | FALSE  | "online"        | "online"      | ""              | []           |
+----------------------------------------------------------------------------------------------------------------------------------------------------------+

3 row available after 57 ms, consumed after another 2 ms

You can change the default database by using initial.dbms.default_database, and restarting the server.

In Community Edition, the default database is the only database available, other than the system database.

Create a database

Example 4. CREATE DATABASE
neo4j@system> CREATE DATABASE sales;
0 rows available after 108 ms, consumed after another 0 ms
neo4j@system> SHOW DATABASES;

In standalone mode:

+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| name     | type       | aliases | access       | address          | role      | writer | requestedStatus | currentStatus | statusMessage | default | home  | constituents |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| "neo4j"  | "standard" | []      | "read-write" | "localhost:7687" | "primary" | TRUE   | "online"        | "online"      | ""            | TRUE    | TRUE  | []           |
| "system" | "system"   | []      | "read-write" | "localhost:7687" | "primary" | TRUE   | "online"        | "online"      | ""            | FALSE   | FALSE | []           |
| "sales"  | "standard" | []      | "read-write" | "localhost:7687" | "primary" | TRUE   | "online"        | "online"      | ""            | FALSE   | FALSE | []           |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

3 rows available after 4 ms, consumed after another 1 ms

Or in a cluster:

+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| name     | type       | aliases | access       | address          | role      | writer | requestedStatus | currentStatus | statusMessage | default | home  | constituents |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| "neo4j"  | "standard" | []      | "read-write" | "localhost:7687" | "primary" | TRUE   | "online"        | "online"      | ""            | TRUE    | TRUE  | []           |
| "neo4j"  | "standard" | []      | "read-write" | "localhost:7688" | "primary" | FALSE  | "online"        | "online"      | ""            | TRUE    | TRUE  | []           |
| "neo4j"  | "standard" | []      | "read-write" | "localhost:7689" | "primary" | FALSE  | "online"        | "online"      | ""            | TRUE    | TRUE  | []           |
| "system" | "system"   | []      | "read-write" | "localhost:7687" | "primary" | FALSE  | "online"        | "online"      | ""            | FALSE   | FALSE | []           |
| "system" | "system"   | []      | "read-write" | "localhost:7688" | "primary" | TRUE   | "online"        | "online"      | ""            | FALSE   | FALSE | []           |
| "system" | "system"   | []      | "read-write" | "localhost:7689" | "primary" | FALSE  | "online"        | "online"      | ""            | FALSE   | FALSE | []           |
| "sales"  | "standard" | []      | "read-write" | "localhost:7687" | "primary" | FALSE  | "online"        | "online"      | ""            | FALSE   | FALSE | []           |
| "sales"  | "standard" | []      | "read-write" | "localhost:7688" | "primary" | FALSE  | "online"        | "online"      | ""            | FALSE   | FALSE | []           |
| "sales"  | "standard" | []      | "read-write" | "localhost:7689" | "primary" | TRUE   | "online"        | "online"      | ""            | FALSE   | FALSE | []           |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

9 rows available after 4 ms, consumed after another 1 ms

Switch a database

Example 5. :use <database-name>
neo4j@system> :use sales
neo4j@sales>

Create or replace a database

Example 6. CREATE OR REPLACE DATABASE
neo4j@sales> match (n) return count(n) as countNode;
+-----------+
| countNode |
+-----------+
| 115       |
+-----------+

1 row available after 12 ms, consumed after another 0 ms
neo4j@system> CREATE OR REPLACE DATABASE sales;
0 rows available after 64 ms, consumed after another 0 ms
neo4j@system> SHOW DATABASES;

In standalone mode:

+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| name     | type       | aliases | access       | address          | role      | writer | requestedStatus | currentStatus | statusMessage | default | home  | constituents |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| "neo4j"  | "standard" | []      | "read-write" | "localhost:7687" | "primary" | TRUE   | "online"        | "online"      | ""            | TRUE    | TRUE  | []           |
| "system" | "system"   | []      | "read-write" | "localhost:7687" | "primary" | TRUE   | "online"        | "online"      | ""            | FALSE   | FALSE | []           |
| "sales"  | "standard" | []      | "read-write" | "localhost:7687" | "primary" | TRUE   | "online"        | "online"      | ""            | FALSE   | FALSE | []           |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

3 rows available after 2 ms, consumed after another 2 ms

Or in a cluster:

+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| name     | type       | aliases | access       | address          | role      | writer | requestedStatus | currentStatus | statusMessage | default   | home  | constituents |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| "neo4j"  | "standard" | []      | "read-write" | "localhost:7687" | "primary" | TRUE   | "online"        | "online"      | ""            | TRUE      | TRUE  | []           |
| "neo4j"  | "standard" | []      | "read-write" | "localhost:7688" | "primary" | FALSE  | "online"        | "online"      | ""            | TRUE      | TRUE  | []           |
| "neo4j"  | "standard" | []      | "read-write" | "localhost:7689" | "primary" | FALSE  | "online"        | "online"      | ""            | TRUE      | TRUE  | []           |
| "system" | "system"   | []      | "read-write" | "localhost:7687" | "primary" | FALSE  | "online"        | "online"      | ""            | FALSE     | FALSE | []           |
| "system" | "system"   | []      | "read-write" | "localhost:7688" | "primary" | TRUE   | "online"        | "online"      | ""            | FALSE     | FALSE | []           |
| "system" | "system"   | []      | "read-write" | "localhost:7689" | "primary" | FALSE  | "online"        | "online"      | ""            | FALSE     | FALSE | []           |
| "sales"  | "standard" | []      | "read-write" | "localhost:7687" | "primary" | FALSE  | "online"        | "online"      | ""            | FALSE     | FALSE | []           |
| "sales"  | "standard" | []      | "read-write" | "localhost:7688" | "primary" | FALSE  | "online"        | "online"      | ""            | FALSE     | FALSE | []           |
| "sales"  | "standard" | []      | "read-write" | "localhost:7689" | "primary" | TRUE   | "online"        | "online"      | ""            | FALSE     | FALSE | []           |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

9 rows available after 2 ms, consumed after another 2 ms
neo4j@system> :use sales
neo4j@sales> match (n) return count(n) as countNode;
+-----------+
| countNode |
+-----------+
| 0         |
+-----------+

1 row available after 15 ms, consumed after another 1 ms

Stop a database

Example 7. STOP DATABASE
neo4j@system> STOP DATABASE sales;
0 rows available after 18 ms, consumed after another 6 ms
neo4j@system> SHOW DATABASES;

In standalone mode:

+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| name     | type       | aliases | access       | address          | role      | writer | requestedStatus | currentStatus | statusMessage | default | home  | constituents |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| "neo4j"  | "standard" | []      | "read-write" | "localhost:7687" | "primary" | TRUE   | "online"        | "online"      | ""            | TRUE    | TRUE  | []           |
| "system" | "system"   | []      | "read-write" | "localhost:7687" | "primary" | TRUE   | "online"        | "online"      | ""            | FALSE   | FALSE | []           |
| "sales"  | "standard" | []      | "read-write" | "localhost:7687" | "primary" | TRUE   | "offline"       | "offline"     | ""            | FALSE   | FALSE | []           |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

3 rows available after 2 ms, consumed after another 1 ms

Or in a cluster:

+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| name     | type       | aliases | access       | address          | role      | writer | requestedStatus | currentStatus | statusMessage | default | home  | constituents |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| "neo4j"  | "standard" | []      | "read-write" | "localhost:7687" | "primary" | TRUE   | "online"        | "online"      | ""            | TRUE    | TRUE  | []           |
| "neo4j"  | "standard" | []      | "read-write" | "localhost:7688" | "primary" | FALSE  | "online"        | "online"      | ""            | TRUE    | TRUE  | []           |
| "neo4j"  | "standard" | []      | "read-write" | "localhost:7689" | "primary" | FALSE  | "online"        | "online"      | ""            | TRUE    | TRUE  | []           |
| "system" | "system"   | []      | "read-write" | "localhost:7687" | "primary" | FALSE  | "online"        | "online"      | ""            | FALSE   | FALSE | []           |
| "system" | "system"   | []      | "read-write" | "localhost:7688" | "primary" | TRUE   | "online"        | "online"      | ""            | FALSE   | FALSE | []           |
| "system" | "system"   | []      | "read-write" | "localhost:7689" | "primary" | FALSE  | "online"        | "online"      | ""            | FALSE   | FALSE | []           |
| "sales"  | "standard" | []      | "read-write" | "localhost:7687" | "unknown" | FALSE  | "offline"       | "offline"     | ""            | FALSE   | FALSE | []           |
| "sales"  | "standard" | []      | "read-write" | "localhost:7688" | "unknown" | FALSE  | "offline"       | "offline"     | ""            | FALSE   | FALSE | []           |
| "sales"  | "standard" | []      | "read-write" | "localhost:7689" | "unknown" | FALSE  | "offline"       | "offline"     | ""            | FALSE   | FALSE | []           |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

9 rows available after 2 ms, consumed after another 1 ms
neo4j@system> :use sales
Unable to get a routing table for database 'sales' because this database is unavailable
neo4j@sales[UNAVAILABLE]>

Start a database

Example 8. START DATABASE
neo4j@sales[UNAVAILABLE]> :use system
neo4j@system> START DATABASE sales;
0 rows available after 21 ms, consumed after another 1 ms
neo4j@system> SHOW DATABASES;

In standalone mode:

+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| name     | type       | aliases | access       | address          | role      | writer | requestedStatus | currentStatus | statusMessage | default | home  | constituents |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| "neo4j"  | "standard" | []      | "read-write" | "localhost:7687" | "primary" | TRUE   | "online"        | "online"      | ""            | TRUE    | TRUE  | []           |
| "system" | "system"   | []      | "read-write" | "localhost:7687" | "primary" | TRUE   | "online"        | "online"      | ""            | FALSE   | FALSE | []           |
| "sales"  | "standard" | []      | "read-write" | "localhost:7687" | "primary" | TRUE   | "online"        | "online"      | ""            | FALSE   | FALSE | []           |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

3 rows available after 2 ms, consumed after another 1 ms

Or in a cluster:

+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| name     | type       | aliases | access       | address          | role      | writer | requestedStatus | currentStatus | statusMessage | default | home  | constituents |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| "neo4j"  | "standard" | []      | "read-write" | "localhost:7687" | "primary" | TRUE   | "online"        | "online"      | ""            | TRUE    | TRUE  | []           |
| "neo4j"  | "standard" | []      | "read-write" | "localhost:7688" | "primary" | FALSE  | "online"        | "online"      | ""            | TRUE    | TRUE  | []           |
| "neo4j"  | "standard" | []      | "read-write" | "localhost:7689" | "primary" | FALSE  | "online"        | "online"      | ""            | TRUE    | TRUE  | []           |
| "system" | "system"   | []      | "read-write" | "localhost:7687" | "primary" | FALSE  | "online"        | "online"      | ""            | FALSE   | FALSE | []           |
| "system" | "system"   | []      | "read-write" | "localhost:7688" | "primary" | TRUE   | "online"        | "online"      | ""            | FALSE   | FALSE | []           |
| "system" | "system"   | []      | "read-write" | "localhost:7689" | "primary" | FALSE  | "online"        | "online"      | ""            | FALSE   | FALSE | []           |
| "sales"  | "standard" | []      | "read-write" | "localhost:7687" | "primary" | FALSE  | "online"        | "online"      | ""            | FALSE   | FALSE | []           |
| "sales"  | "standard" | []      | "read-write" | "localhost:7688" | "primary" | FALSE  | "online"        | "online"      | ""            | FALSE   | FALSE | []           |
| "sales"  | "standard" | []      | "read-write" | "localhost:7689" | "primary" | TRUE   | "online"        | "online"      | ""            | FALSE   | FALSE | []           |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

9 rows available after 2 ms, consumed after another 1 ms

Drop or remove a database

Example 9. DROP DATABASE
neo4j@system> DROP DATABASE sales;
0 rows available after 82 ms, consumed after another 1 ms
neo4j@system> SHOW DATABASES;
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| name     | type       | aliases | access       | address          | role      | writer | requestedStatus | currentStatus | statusMessage | default | home  | constituents |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| "neo4j"  | "standard" | []      | "read-write" | "localhost:7687" | "primary" | TRUE   | "online"        | "online"      | ""            | TRUE    | TRUE  | []           |
| "system" | "system"   | []      | "read-write" | "localhost:7687" | "primary" | TRUE   | "online"        | "online"      | ""            | FALSE   | FALSE | []           |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

2 rows available after 6 ms, consumed after another 0 ms