6.3. Queries

This section provides examples of queries and Cypher commands that can be used to create and manage multiple active databases.

This section describes the following:

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

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.

6.3.1. Show the status of a specific database

Example 6.1. SHOW DATABASE
neo4j@system> SHOW DATABASE neo4j;
+-----------------------------------------------------------------------------------------------+
| name    | address          | role         | requestedStatus | currentStatus | error | default |
+-----------------------------------------------------------------------------------------------+
| "neo4j" | "localhost:7687" | "standalone" | "online"        | "online"      | ""    | TRUE    |
+-----------------------------------------------------------------------------------------------+

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

6.3.2. Show the status of all databases

Example 6.2. SHOW DATABASES
neo4j@system> SHOW DATABASES;
+------------------------------------------------------------------------------------------------+
| name     | address          | role         | requestedStatus | currentStatus | error | default |
+------------------------------------------------------------------------------------------------+
| "neo4j"  | "localhost:7687" | "standalone" | "online"        | "online"      | ""    | TRUE    |
| "system" | "localhost:7687" | "standalone" | "online"        | "online"      | ""    | FALSE   |
+------------------------------------------------------------------------------------------------+

2 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.

6.3.3. 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 6.3. SHOW DEFAULT DATABASE
neo4j@system> SHOW DEFAULT DATABASE;
+-------------------------------------------------------------------------------------+
| name    | address          | role         | requestedStatus | currentStatus | error |
+-------------------------------------------------------------------------------------+
| "neo4j" | "localhost:7687" | "standalone" | "online"        | "online"      | ""    |
+-------------------------------------------------------------------------------------+

1 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.

6.3.4. Create a database

Example 6.4. CREATE DATABASE
neo4j@system> CREATE DATABASE sales;
0 rows available after 108 ms, consumed after another 0 ms
neo4j@system> SHOW DATABASES;
+------------------------------------------------------------------------------------------------+
| name     | address          | role         | requestedStatus | currentStatus | error | default |
+------------------------------------------------------------------------------------------------+
| "neo4j"  | "localhost:7687" | "standalone" | "online"        | "online"      | ""    | TRUE    |
| "system" | "localhost:7687" | "standalone" | "online"        | "online"      | ""    | FALSE   |
| "sales"  | "localhost:7687" | "standalone" | "online"        | "online"      | ""    | FALSE   |
+------------------------------------------------------------------------------------------------+

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

6.3.5. Switch a database

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

6.3.6. Create or replace a database

Example 6.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;
+------------------------------------------------------------------------------------------------+
| name     | address          | role         | requestedStatus | currentStatus | error | default |
+------------------------------------------------------------------------------------------------+
| "neo4j"  | "localhost:7687" | "standalone" | "online"        | "online"      | ""    | TRUE    |
| "system" | "localhost:7687" | "standalone" | "online"        | "online"      | ""    | FALSE   |
| "sales"  | "localhost:7687" | "standalone" | "online"        | "online"      | ""    | FALSE   |
+------------------------------------------------------------------------------------------------+

3 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

6.3.7. Stop a database

Example 6.7. STOP DATABASE
neo4j@system> STOP DATABASE sales;
0 rows available after 18 ms, consumed after another 6 ms
neo4j@system> SHOW DATABASES;
+------------------------------------------------------------------------------------------------+
| name     | address          | role         | requestedStatus | currentStatus | error | default |
+------------------------------------------------------------------------------------------------+
| "neo4j"  | "localhost:7687" | "standalone" | "online"        | "online"      | ""    | TRUE    |
| "system" | "localhost:7687" | "standalone" | "online"        | "online"      | ""    | FALSE   |
| "sales"  | "localhost:7687" | "standalone" | "offline"       | "offline"     | ""    | FALSE   |
+------------------------------------------------------------------------------------------------+

3 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]>

6.3.8. Start a database

Example 6.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;
+------------------------------------------------------------------------------------------------+
| name     | address          | role         | requestedStatus | currentStatus | error | default |
+------------------------------------------------------------------------------------------------+
| "neo4j"  | "localhost:7687" | "standalone" | "online"        | "online"      | ""    | TRUE    |
| "system" | "localhost:7687" | "standalone" | "online"        | "online"      | ""    | FALSE   |
| "sales"  | "localhost:7687" | "standalone" | "online"        | "online"      | ""    | FALSE   |
+------------------------------------------------------------------------------------------------+

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

6.3.9. Drop or remove a database

Example 6.9. DROP DATABASE
neo4j@system> DROP DATABASE sales;
0 rows available after 82 ms, consumed after another 1 ms
neo4j@system> SHOW DATABASES;
+------------------------------------------------------------------------------------------------+
| name     | address          | role         | requestedStatus | currentStatus | error | default |
+------------------------------------------------------------------------------------------------+
| "neo4j"  | "localhost:7687" | "standalone" | "online"        | "online"      | ""    | TRUE    |
| "system" | "localhost:7687" | "standalone" | "online"        | "online"      | ""    | FALSE   |
+------------------------------------------------------------------------------------------------+

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