# Neo4j

MemGQL supports two Neo4j connector modes:

- **`neo4j`** — passthrough, forwards queries as-is (Cypher)
- **`neo4j-gql`** — translates GQL to Cypher before execution

## 1. Start Neo4j

```bash
docker network create memgql-net

docker run -d --rm \
    --name neo4j-dev \
    --network memgql-net \
    -p 7474:7474 \
    -p 7697:7687 \
    --env NEO4J_AUTH=neo4j/password \
    neo4j:5
```

## 2. Start MemGQL (GQL mode)

```bash
docker run --rm \
    --name memgql \
    --network memgql-net \
    --stop-timeout 2 \
    -p 7688:7688 \
    --env CONNECTOR_TYPE=neo4j-gql \
    --env NEO4J_URI=neo4j-dev:7687 \
    --env NEO4J_USER=neo4j \
    --env NEO4J_PASS=password \
    --env BOLT_LISTEN_ADDR=0.0.0.0:7688 \
    memgraph/memgql:latest
```

For passthrough mode, use `CONNECTOR_TYPE=neo4j` instead.

## 3. Connect

```bash
mgconsole --port 7688
```

## 4. Seed data

```gql
INSERT
  (alice:Person {name: "Alice", age: 30}),
  (bob:Person {name: "Bob", age: 25}),
  (acme:Company {name: "Acme Corp"}),
  (alice)-[:KNOWS]->(bob),
  (alice)-[:WORKS_AT {role: "Engineer"}]->(acme);
```

## 5. Query

```gql
MATCH (p:Person) RETURN p.name, p.age;
```

```gql
MATCH (p:Person)-[:WORKS_AT]->(c:Company) RETURN p.name, c.name;
```

```gql
MATCH (a:Person)-[:KNOWS]->(b:Person) RETURN a.name, b.name;
```

For environment variables, see [Reference](https://memgraph.com/docs/memgraph-zero/memgql/reference#neo4j-neo4j-neo4j-gql).

## Supported GQL features

GQL-specific syntax (INSERT, LOCAL_DATETIME, etc.) only works on `neo4j-gql`; the plain `neo4j` connector is Cypher passthrough.

| Feature                                       | Neo4j |
|-----------------------------------------------|-------|
| `MATCH` / `WHERE` / `RETURN`                  | ✓     |
| Pattern-level `WHERE` (`MATCH (n WHERE …)`)   | ✓     |
| Multi-MATCH (cross-join)                      | ✓     |
| `OPTIONAL MATCH`                              | ✓     |
| `WITH` pipeline boundary                      | ✓     |
| `WITH DISTINCT` / `WITH … ORDER BY … LIMIT N` | ✓     |
| Chained `WITH … WITH …`                       | ✓     |
| Whole-node `WITH n` carry-through             | ✓     |
| Typed edge `(a)-[r:R]->(b)`                   | ✓     |
| Untyped edge `()-[]->(b)`                     | ✓     |
| `UNION` / `UNION ALL` / `UNION DISTINCT`      | ✓     |
| `INTERSECT` / `EXCEPT`                        | ✗     |
| Quantified path `(){m,n}` — bounded           | ✓     |
| Quantified path `(){m,}` — unbounded          | ✓     |
| Shortest-path (`ALL SHORTEST` / `SHORTEST k`) | ✓     |
| Path binding `MATCH p = (…) RETURN p`         | ✓     |
| Whole-node `RETURN n`                         | ✓     |
| Map projections `RETURN n {.a, .b}`           | ✓     |
| `IN` list membership `WHERE x IN [...]`       | ✓     |
| `STARTS WITH` / `ENDS WITH` / `CONTAINS`      | ✓     |
| `collect()` aggregate                         | ✓     |
| `count`, `sum`, `avg`, `min`, `max`           | ✓     |
| `COUNT(DISTINCT …)`                           | ✓     |
| Arithmetic `+ - * / %`                        | ✓     |
| `CASE WHEN … THEN … ELSE … END`               | ✓     |
| `COALESCE`, `NULLIF`                          | ✓     |
| Temporals (`date`, `LOCAL_DATETIME`, …)       | ✓     |
| `INSERT (a {…}) RETURN a.x`                   | ✓     |
| `DELETE` / `DETACH DELETE`                    | ✓     |
| `SET` / `REMOVE` (property update / delete)   | ✓     |
