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    | aliases | access       | address          | role         | requestedStatus | currentStatus | error | default | home  |
+--------------------------------------------------------------------------------------------------------------------------------+
| "neo4j" | []      | "read-write" | "localhost:7687" | "standalone" | "online"        | "online"      | ""    | TRUE    | TRUE  |
+--------------------------------------------------------------------------------------------------------------------------------+

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

Or in a Causal Cluster:

+--------------------------------------------------------------------------------------------------------------------------------+
| name    | aliases | access       | address          | role       | requestedStatus | currentStatus | error | default   | home  |
+--------------------------------------------------------------------------------------------------------------------------------+
| "neo4j" | []      | "read-write" | "localhost:7687" | "leader"   | "online"        | "online"      | ""    | TRUE      | TRUE  |
| "neo4j" | []      | "read-write" | "localhost:7688" | "follower" | "online"        | "online"      | ""    | TRUE      | TRUE  |
| "neo4j" | []      | "read-write" | "localhost:7689" | "follower" | "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     | aliases | access       | address          | role         | requestedStatus | currentStatus | error | default | home  |
+---------------------------------------------------------------------------------------------------------------------------------+
| "neo4j"  | []      | "read-write" | "localhost:7687" | "standalone" | "online"        | "online"      | ""    | TRUE    | TRUE  |
| "system" | []      | "read-write" | "localhost:7687" | "standalone" | "online"        | "online"      | ""    | FALSE   | FALSE |
+---------------------------------------------------------------------------------------------------------------------------------+

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

Or in a Causal Cluster:

+---------------------------------------------------------------------------------------------------------------------------------+
| name     | aliases | access       | address          | role       | requestedStatus | currentStatus | error | default   | home  |
+---------------------------------------------------------------------------------------------------------------------------------+
| "neo4j"  | []      | "read-write" | "localhost:7687" | "leader"   | "online"        | "online"      | ""    | TRUE      | TRUE  |
| "neo4j"  | []      | "read-write" | "localhost:7688" | "follower" | "online"        | "online"      | ""    | TRUE      | TRUE  |
| "neo4j"  | []      | "read-write" | "localhost:7689" | "follower" | "online"        | "online"      | ""    | TRUE      | TRUE  |
| "system" | []      | "read-write" | "localhost:7687" | "follower" | "online"        | "online"      | ""    | FALSE     | FALSE |
| "system" | []      | "read-write" | "localhost:7688" | "leader"   | "online"        | "online"      | ""    | FALSE     | FALSE |
| "system" | []      | "read-write" | "localhost:7689" | "follower" | "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 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    | aliases | access       | address          | role         | requestedStatus | currentStatus | error |
+--------------------------------------------------------------------------------------------------------------+
| "neo4j" | []      | "read-write" | "localhost:7687" | "standalone" | "online"        | "online"      | ""    |
+--------------------------------------------------------------------------------------------------------------+

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

Or in a Causal Cluster:

+--------------------------------------------------------------------------------------------------------------+
| name    | aliases | access       | address          | role       | requestedStatus | currentStatus | error   |
+--------------------------------------------------------------------------------------------------------------+
| "neo4j" | []      | "read-write" | "localhost:7687" | "follower" | "online"        | "online"      | ""      |
| "neo4j" | []      | "read-write" | "localhost:7688" | "leader"   | "online"        | "online"      | ""      |
| "neo4j" | []      | "read-write" | "localhost:7689" | "follower" | "online"        | "online"      | ""      |
+--------------------------------------------------------------------------------------------------------------+

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

You can change the default database by using 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     | aliases | access       | address          | role         | requestedStatus | currentStatus | error | default | home  |
+---------------------------------------------------------------------------------------------------------------------------------+
| "neo4j"  | []      | "read-write" | "localhost:7687" | "standalone" | "online"        | "online"      | ""    | TRUE    | TRUE  |
| "system" | []      | "read-write" | "localhost:7687" | "standalone" | "online"        | "online"      | ""    | FALSE   | FALSE |
| "sales"  | []      | "read-write" | "localhost:7687" | "standalone" | "online"        | "online"      | ""    | FALSE   | FALSE |
+---------------------------------------------------------------------------------------------------------------------------------+

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

Or in a Causal Cluster:

+---------------------------------------------------------------------------------------------------------------------------------+
| name     | aliases | access       | address          | role       | requestedStatus | currentStatus | error | default   | home  |
+---------------------------------------------------------------------------------------------------------------------------------+
| "neo4j"  | []      | "read-write" | "localhost:7687" | "leader"   | "online"        | "online"      | ""    | TRUE      | TRUE  |
| "neo4j"  | []      | "read-write" | "localhost:7688" | "follower" | "online"        | "online"      | ""    | TRUE      | TRUE  |
| "neo4j"  | []      | "read-write" | "localhost:7689" | "follower" | "online"        | "online"      | ""    | TRUE      | TRUE  |
| "system" | []      | "read-write" | "localhost:7687" | "follower" | "online"        | "online"      | ""    | FALSE     | FALSE |
| "system" | []      | "read-write" | "localhost:7688" | "leader"   | "online"        | "online"      | ""    | FALSE     | FALSE |
| "system" | []      | "read-write" | "localhost:7689" | "follower" | "online"        | "online"      | ""    | FALSE     | FALSE |
| "sales"  | []      | "read-write" | "localhost:7687" | "follower" | "online"        | "online"      | ""    | FALSE     | FALSE |
| "sales"  | []      | "read-write" | "localhost:7688" | "follower" | "online"        | "online"      | ""    | FALSE     | FALSE |
| "sales"  | []      | "read-write" | "localhost:7689" | "leader"   | "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     | aliases | access       | address          | role         | requestedStatus | currentStatus | error | default | home  |
+---------------------------------------------------------------------------------------------------------------------------------+
| "neo4j"  | []      | "read-write" | "localhost:7687" | "standalone" | "online"        | "online"      | ""    | TRUE    | TRUE  |
| "system" | []      | "read-write" | "localhost:7687" | "standalone" | "online"        | "online"      | ""    | FALSE   | FALSE |
| "sales"  | []      | "read-write" | "localhost:7687" | "standalone" | "online"        | "online"      | ""    | FALSE   | FALSE |
+---------------------------------------------------------------------------------------------------------------------------------+

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

Or in a Causal Cluster:

+---------------------------------------------------------------------------------------------------------------------------------+
| name     | aliases | access       | address          | role       | requestedStatus | currentStatus | error | default   | home  |
+---------------------------------------------------------------------------------------------------------------------------------+
| "neo4j"  | []      | "read-write" | "localhost:7687" | "leader"   | "online"        | "online"      | ""    | TRUE      | TRUE  |
| "neo4j"  | []      | "read-write" | "localhost:7688" | "follower" | "online"        | "online"      | ""    | TRUE      | TRUE  |
| "neo4j"  | []      | "read-write" | "localhost:7689" | "follower" | "online"        | "online"      | ""    | TRUE      | TRUE  |
| "system" | []      | "read-write" | "localhost:7687" | "follower" | "online"        | "online"      | ""    | FALSE     | FALSE |
| "system" | []      | "read-write" | "localhost:7688" | "leader"   | "online"        | "online"      | ""    | FALSE     | FALSE |
| "system" | []      | "read-write" | "localhost:7689" | "follower" | "online"        | "online"      | ""    | FALSE     | FALSE |
| "sales"  | []      | "read-write" | "localhost:7687" | "follower" | "online"        | "online"      | ""    | FALSE     | FALSE |
| "sales"  | []      | "read-write" | "localhost:7688" | "follower" | "online"        | "online"      | ""    | FALSE     | FALSE |
| "sales"  | []      | "read-write" | "localhost:7689" | "leader"   | "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     | aliases | access       | address          | role         | requestedStatus | currentStatus | error | default | home  |
+---------------------------------------------------------------------------------------------------------------------------------+
| "neo4j"  | []      | "read-write" | "localhost:7687" | "standalone" | "online"        | "online"      | ""    | TRUE    | TRUE  |
| "system" | []      | "read-write" | "localhost:7687" | "standalone" | "online"        | "online"      | ""    | FALSE   | FALSE |
| "sales"  | []      | "read-write" | "localhost:7687" | "standalone" | "offline"       | "offline"     | ""    | FALSE   | FALSE |
+---------------------------------------------------------------------------------------------------------------------------------+

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

Or in a Causal Cluster:

+---------------------------------------------------------------------------------------------------------------------------------+
| name     | aliases | access       | address          | role       | requestedStatus | currentStatus | error | default   | home  |
+---------------------------------------------------------------------------------------------------------------------------------+
| "neo4j"  | []      | "read-write" | "localhost:7687" | "leader"   | "online"        | "online"      | ""    | TRUE      | TRUE  |
| "neo4j"  | []      | "read-write" | "localhost:7688" | "follower" | "online"        | "online"      | ""    | TRUE      | TRUE  |
| "neo4j"  | []      | "read-write" | "localhost:7689" | "follower" | "online"        | "online"      | ""    | TRUE      | TRUE  |
| "system" | []      | "read-write" | "localhost:7687" | "follower" | "online"        | "online"      | ""    | FALSE     | FALSE |
| "system" | []      | "read-write" | "localhost:7688" | "leader"   | "online"        | "online"      | ""    | FALSE     | FALSE |
| "system" | []      | "read-write" | "localhost:7689" | "follower" | "online"        | "online"      | ""    | FALSE     | FALSE |
| "sales"  | []      | "read-write" | "localhost:7687" | "unknown"  | "offline"       | "offline"     | ""    | FALSE     | FALSE |
| "sales"  | []      | "read-write" | "localhost:7688" | "unknown"  | "offline"       | "offline"     | ""    | FALSE     | FALSE |
| "sales"  | []      | "read-write" | "localhost:7689" | "unknown"  | "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     | aliases | access       | address          | role         | requestedStatus | currentStatus | error | default | home  |
+---------------------------------------------------------------------------------------------------------------------------------+
| "neo4j"  | []      | "read-write" | "localhost:7687" | "standalone" | "online"        | "online"      | ""    | TRUE    | TRUE  |
| "system" | []      | "read-write" | "localhost:7687" | "standalone" | "online"        | "online"      | ""    | FALSE   | FALSE |
| "sales"  | []      | "read-write" | "localhost:7687" | "standalone" | "online"        | "online"      | ""    | FALSE   | FALSE |
+---------------------------------------------------------------------------------------------------------------------------------+

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

Or in a Causal Cluster:

+---------------------------------------------------------------------------------------------------------------------------------+
| name     | aliases | access       | address          | role       | requestedStatus | currentStatus | error | default   | home  |
+---------------------------------------------------------------------------------------------------------------------------------+
| "neo4j"  | []      | "read-write" | "localhost:7687" | "leader"   | "online"        | "online"      | ""    | TRUE      | TRUE  |
| "neo4j"  | []      | "read-write" | "localhost:7688" | "follower" | "online"        | "online"      | ""    | TRUE      | TRUE  |
| "neo4j"  | []      | "read-write" | "localhost:7689" | "follower" | "online"        | "online"      | ""    | TRUE      | TRUE  |
| "system" | []      | "read-write" | "localhost:7687" | "follower" | "online"        | "online"      | ""    | FALSE     | FALSE |
| "system" | []      | "read-write" | "localhost:7688" | "leader"   | "online"        | "online"      | ""    | FALSE     | FALSE |
| "system" | []      | "read-write" | "localhost:7689" | "follower" | "online"        | "online"      | ""    | FALSE     | FALSE |
| "sales"  | []      | "read-write" | "localhost:7687" | "follower" | "online"        | "online"      | ""    | FALSE     | FALSE |
| "sales"  | []      | "read-write" | "localhost:7688" | "follower" | "online"        | "online"      | ""    | FALSE     | FALSE |
| "sales"  | []      | "read-write" | "localhost:7689" | "leader"   | "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     | aliases | access       | address          | role         | requestedStatus | currentStatus | error | default | home  |
+---------------------------------------------------------------------------------------------------------------------------------+
| "neo4j"  | []      | "read-write" | "localhost:7687" | "standalone" | "online"        | "online"      | ""    | TRUE    | TRUE  |
| "system" | []      | "read-write" | "localhost:7687" | "standalone" | "online"        | "online"      | ""    | FALSE   | FALSE |
+---------------------------------------------------------------------------------------------------------------------------------+

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