I am using NodeJS and the neo4j-driver package. On server startup I need to ensure that a specific database exists in my neo4j cluster. I therefore implemented this method:
export const ensureAdminDatabaseExists = async () => {
const session = neo4j
.driver(
NEO4J_CONNECTION_URL,
neo4j.auth.basic(NEO4J_USERNAME, NEO4J_PASSWORD)
)
.session();
await session.writeTransaction((tx) =>
tx.run('CREATE DATABASE $dbName IF NOT EXISTS', { dbName: 'admin' })
);
await session.close();
};
If no such database exists in Neo4j and I call this method several times in parallel, then at least one of the transactions will fail with the following error message:
Neo4jError: Failed to create the specified database 'admin': Database already exists.
However, if the database exists on startup then no transactions fail. I, therefore, question if the CREATE DATABASE
query is transactional.