Ihr Graphmodell refaktorieren und weiterentwickeln
Lernen Sie, ein Neo4j-Graphmodell mithilfe von Refactoring-Mustern und neu strukturierten Abfragen im Laufe der Zeit sicher weiterzuentwickeln.
Ihr Graphmodell refaktorieren und weiterentwickeln ist eine kostenlose Neo4j Graph Database Fundamentals-Lektion auf CoddyKit. Dies ist Lektion 4 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Neo4j Graph Database Fundamentals-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Neo4j Graph Database Fundamentals-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
Models Are Never Final
As applications grow, your graph model will change. New questions demand new structure. Refactoring lets you reshape the graph without losing data.
Property to Node
A common refactor: a property shared by many nodes (like a city name) becomes its own node so it can hold relationships.
MATCH (p:Person)
WHERE p.city IS NOT NULL
MERGE (c:City {name: p.city})
MERGE (p)-[:LIVES_IN]->(c)
REMOVE p.city;Node to Property
The reverse refactor: collapse a rarely-traversed node back into a property when its relationships add no value.
MATCH (p:Person)-[r:LIVES_IN]->(c:City)
SET p.city = c.name
DELETE r;Renaming Relationship Types
To rename a relationship type, create the new one and delete the old. Cypher cannot rename a type in place.
MATCH (a)-[old:KNOWS]->(b)
MERGE (a)-[:FRIEND]->(b)
DELETE old;Adding a New Label
You can introduce a new label to a subset of nodes to support new queries or constraints.
MATCH (p:Person)
WHERE p.age >= 18
SET p:Adult;Splitting a Node
When one node mixes two concerns (e.g. a user and their address), split it into linked nodes for clarity and reuse.
MATCH (u:User)
WHERE u.street IS NOT NULL
CREATE (a:Address {street: u.street, zip: u.zip})
MERGE (u)-[:HAS_ADDRESS]->(a)
REMOVE u.street, u.zip;Merging Duplicate Nodes
Data imports can create duplicates. Use APOC or careful Cypher to merge them, reattaching all relationships to a single surviving node.
MATCH (a:Person {email: 'x@y.com'}), (b:Person {email: 'x@y.com'})
WHERE id(a) < id(b)
WITH a, b
CALL apoc.refactor.mergeNodes([a, b]) YIELD node
RETURN node;Batching Large Refactors
Refactors over millions of nodes should run in batches to avoid huge transactions. APOC's periodic iterate helps.
CALL apoc.periodic.iterate(
'MATCH (p:Person) WHERE p.city IS NOT NULL RETURN p',
'MERGE (c:City {name: p.city}) MERGE (p)-[:LIVES_IN]->(c) REMOVE p.city',
{batchSize: 1000}
);Versioning Your Model
Keep refactor scripts in version control and apply them in order, like database migrations. This makes changes reproducible across environments.
Testing After Refactor
Always validate counts before and after. Compare relationship totals to ensure nothing was orphaned or lost.
MATCH ()-[r:LIVES_IN]->() RETURN count(r) AS livesInCount;Refactor with Confidence
Back up first, refactor in batches, verify counts, and keep scripts versioned. A graph model is a living thing you improve over time.
Quick Check
Test your refactoring knowledge.
Recap
You learned to evolve graph models safely:
- Convert properties to nodes and back
- Rename relationship types by recreating them
- Split nodes and merge duplicates
- Batch large refactors with APOC
- Version scripts and verify counts
Lerne Neo4j Graph Database Fundamentals mit einem KI-Tutor — kostenlos
Schreibe und führe echten Code in deinem Browser aus, bekomme sofortige Hilfe von einem 24/7 KI-Tutor und setze dein Lernen im Web oder in der App fort.
- Kurse
- 12
- Lektionen
- 48
Häufig gestellte Fragen
Ist die Lektion „Ihr Graphmodell refaktorieren und weiterentwickeln“ kostenlos?
Ja — der vollständige Text von „Ihr Graphmodell refaktorieren und weiterentwickeln“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Neo4j Graph Database Fundamentals-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Neo4j Graph Database Fundamentals-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „Ihr Graphmodell refaktorieren und weiterentwickeln“?
Lernen Sie, ein Neo4j-Graphmodell mithilfe von Refactoring-Mustern und neu strukturierten Abfragen im Laufe der Zeit sicher weiterzuentwickeln. Du übst Neo4j Graph Database Fundamentals mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um Neo4j Graph Database Fundamentals zu starten?
Keine Vorkenntnisse erforderlich. Neo4j Graph Database Fundamentals auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 4 von 4.
Wie lange dauert die Lektion „Ihr Graphmodell refaktorieren und weiterentwickeln“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser Neo4j Graph Database Fundamentals-Lektion Code schreiben und ausführen?
Ja. Jede Neo4j Graph Database Fundamentals-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- Grundlagen der Graphdatenmodellierung
- Ihr erstes Graphmodell entwerfen
- Schemaeinschränkungen und Indizes
- Ihr Graphmodell refaktorieren und weiterentwickeln