Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions memgraph-migration-from-neo4j/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
name: memgraph-migration-from-neo4j
description: Guide migrating graph data from Neo4j to Memgraph using the migrate module and a single Cypher query. Use when user wants to migrate from Neo4j, switch to Memgraph, or transfer graph data without CSV export/import.
metadata:
author: memgraph
version: "0.0.1"
---

# Memgraph Migration from Neo4j

Migrate graph data from Neo4j to Memgraph using the built-in `migrate` module. Streams data directly—no CSV exports.

## When to Use

- User wants to migrate from Neo4j to Memgraph
- User asks how to transfer graph data between Neo4j and Memgraph
- User mentions Neo4j migration, data transfer, or switching databases
- User prefers direct streaming over CSV export/import

## Prerequisites

- Memgraph with MAGE (migrate module)
- Neo4j reachable via Bolt; Memgraph and Neo4j on different ports if same host

## Migration Workflow

1. **Create indices** — `:__MigrationNode__` and `:__MigrationNode__(__elementId__)`
2. **Migrate orphan nodes** (if any) — run orphan query before triplets
3. **Migrate triplets** — nodes + relationships via `CALL migrate.neo4j(...) YIELD row MERGE/CREATE`
4. **Clean up** — drop indices, remove `__MigrationNode__` label and `__elementId__` property
5. **Rebuild indices and constraints** — not migrated; add manually

## Key Notes

- Uses `elementId(n)` from Neo4j as stable ID for `MERGE`
- `__MigrationNode__` and `__elementId__` are temporary; remove after migration
- Indices and constraints must be recreated manually
- Direct streaming—no CSV; suitable for large graphs

## Additional Resources

- Full queries and partial migration examples: [references/REFERENCE.md](references/REFERENCE.md)
- [Memgraph docs](https://memgraph.com/docs/data-migration/migrate-from-neo4j/using-single-cypher-query)
65 changes: 65 additions & 0 deletions memgraph-migration-from-neo4j/references/REFERENCE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Neo4j → Memgraph Migration — Reference

Full Cypher queries and details for migration. Requires Memgraph with MAGE (migrate module).

## Step 1: Create migration indices

```cypher
CREATE INDEX ON :__MigrationNode__;
CREATE INDEX ON :__MigrationNode__(__elementId__);
```

## Step 2: Migrate orphan nodes (if any)

Run before triplet migration if the graph has nodes with no relationships:

```cypher
CALL migrate.neo4j(
"MATCH (n) RETURN labels(n) AS node_labels, elementId(n) as node_id, properties(n) as node_props",
{host: "localhost", port: 7687})
YIELD row
MERGE (n:__MigrationNode__ {__elementId__: row.node_id})
SET n:row.node_labels
SET n += row.node_props;
```

## Step 3: Migrate triplets (nodes and relationships)

```cypher
CALL migrate.neo4j(
"MATCH (n)-[r]->(m) RETURN labels(n) AS src_labels, type(r) as rel_type, labels(m) AS dest_labels, elementId(n) AS src_id, elementId(m) AS dest_id, properties(n) AS src_props, properties(r) AS edge_props, properties(m) AS dest_props",
{host: "localhost", port: 7687})
YIELD row
MERGE (n:__MigrationNode__ {__elementId__: row.src_id})
MERGE (m:__MigrationNode__ {__elementId__: row.dest_id})
SET n:row.src_labels
SET m:row.dest_labels
SET n += row.src_props
SET m += row.dest_props
CREATE (n)-[r:row.rel_type]->(m)
SET r += row.edge_props;
```

Adjust `host` and `port` in the config map.

## Step 4: Clean up

```cypher
DROP INDEX ON :__MigrationNode__;
DROP INDEX ON :__MigrationNode__(__elementId__);
MATCH (n) SET n.__elementId__ = null;
```

## Migrate specific data

Partial migration returns rows; use Cypher to create nodes/relationships.

**Nodes with label `Person`:**
```cypher
CALL migrate.neo4j(":Person", {host: "localhost", port: 7687}) YIELD row RETURN row;
```

**Relationships of type `KNOWS`:**
```cypher
CALL migrate.neo4j("[:KNOWS]", {host: "localhost", port: 7687}) YIELD row RETURN row;
```