Neo4j
Neo4j (serviceId neo4j-docker-neo4j) is a graph database that stores data as nodes and relationships rather than tables. In Eyevinn Open Source Cloud (OSC) it is a long-running service instance with up to 10 GiB of storage per instance. License: Apache-2.0.
What it can do
- Store and query highly connected data such as social graphs, recommendation engines, fraud detection, knowledge graphs and network analysis.
- Run Cypher queries and visualize nodes and relationships in the Neo4j Browser web UI.
- Serve applications over the Bolt protocol (port 7687) using the official Neo4j drivers.
Creating an instance
Create the instance with create-service-instance using serviceId: "neo4j-docker-neo4j" and a config object. The instance name must be alphanumeric and at most 20 characters. Neo4j has no dependencies on other OSC services.
Store the credentials as a service secret first with create-service-secret (serviceId: "neo4j-docker-neo4j"), for example a secret neo4jauth with the value neo4j/<your-password>.
{ "name": "mygraph", "Auth": "{{secrets.neo4jauth}}" }
Wait for the instance with wait-for-service-ready and use describe-service-instance to get the instance URL and the Bolt endpoint and port.
With the OSC CLI:
osc create neo4j-docker-neo4j mygraph \
-o Auth="neo4j/mySecurePassword123"
Options
| Option | Required | Type | Meaning |
|---|---|---|---|
| name | Yes | string | Name of the instance. Alphanumeric, at most 20 characters. |
| Auth | No | string | Authentication credentials in the format <username>/<password>, for example neo4j/<your-password>. It sets the database user and password (Neo4j's NEO4J_AUTH). If not set, the default credentials are neo4j/neo4j and Neo4j requires a password change on first login. |
Auth contains a password but is not marked sensitive in the catalog; pass it as {{secrets.NAME}} from a service secret to keep it out of the instance config. A {{secrets.NAME}} reference must be the whole field value, and changing a secret later does not restart a running instance.
Using the instance
Neo4j Browser
Open the instance URL to reach the Neo4j Browser and log in with the credentials from Auth (or neo4j/neo4j and change the password when prompted). From the browser you can run Cypher queries, visualize the graph, import and export data and monitor database performance.
Connect from an application
Neo4j uses the Bolt protocol (port 7687). Use one of the official drivers with the Bolt endpoint from describe-service-instance:
import neo4j from 'neo4j-driver';
const driver = neo4j.driver(
'bolt://<instance-host>:<bolt-port>',
neo4j.auth.basic('neo4j', '<your-password>')
);
const session = driver.session();
const result = await session.run(
'CREATE (p:Person {name: $name}) RETURN p',
{ name: 'Alice' }
);
await session.close();
await driver.close();
Example Cypher queries
// Create nodes and a relationship
CREATE (alice:Person {name: 'Alice'})
CREATE (bob:Person {name: 'Bob'})
CREATE (alice)-[:KNOWS]->(bob)
// Find all people Alice knows
MATCH (alice:Person {name: 'Alice'})-[:KNOWS]->(friend)
RETURN friend.name
// Find shortest path between two nodes
MATCH path = shortestPath(
(alice:Person {name: 'Alice'})-[*]-(target:Person {name: 'Bob'})
)
RETURN path
Limitations
- Storage is limited to 10 GiB per instance.