Importer et exporter des données
Découvrez différentes méthodes pour charger des données dans Neo4j depuis des sources externes et exporter des données de graphe pour d’autres usages.
Importer et exporter des données est une leçon Neo4j Graph Database Fundamentals gratuite sur CoddyKit. Ceci est la leçon 2 sur 4. Tu peux lire la leçon complète ci-dessous gratuitement — puis la pratiquer en direct dans le navigateur avec un éditeur de code intégré et un tuteur IA 24/7. Elle fait partie du parcours d'apprentissage Neo4j Graph Database Fundamentals, et ta progression se synchronise sur le web et l'application CoddyKit. Le cours Neo4j Graph Database Fundamentals comprend 4 leçons au total.
Certaines parties de cette leçon n'ont pas encore été traduites et s'affichent en anglais.
Moving Data In & Out
In this lesson, we'll explore how to get data into your Neo4j graph database and how to extract it for other uses. This is crucial for integrating Neo4j with existing systems, migrating data, or preparing it for analysis.
Importing Data: An Overview
Bringing external data into Neo4j is a common task. There are several powerful methods:
LOAD CSV: For structured data from CSV files.- APOC Procedures: For more complex formats like JSON, XML, or data from external databases.
- Connectors & Drivers: Programmatic import via application code.
We'll focus on the first two methods.
LOAD CSV: The Basics
The LOAD CSV Cypher clause is your go-to for importing data from CSV files. It lets you specify the file path, handle headers, and access each row's data.
Here's a basic structure to read a CSV and return its rows:
LOAD CSV WITH HEADERS FROM 'file:///users.csv' AS row
RETURN row;Creating Nodes from CSV
Let's say you have a users.csv file with id,name,email columns. You can use LOAD CSV to create User nodes:
LOAD CSV WITH HEADERS FROM 'file:///users.csv' AS row
CREATE (:User {id: row.id, name: row.name, email: row.email});Creating Relationships from CSV
You can also create relationships. If you have a follows.csv with followerId,followedId, you can connect existing User nodes:
- We use
MATCHto find the existing nodes. CREATEthen forms the relationship between them.
LOAD CSV WITH HEADERS FROM 'file:///follows.csv' AS row
MATCH (u1:User {id: row.followerId})
MATCH (u2:User {id: row.followedId})
CREATE (u1)-[:FOLLOWS]->(u2);Beyond CSV: APOC for Import
For more complex import scenarios, such as JSON or XML files, or data from external databases, the APOC (Awesome Procedures On Cypher) library is invaluable. APOC extends Cypher with hundreds of new procedures and functions.
You'll need to install the APOC plugin for your Neo4j instance to use these features.
Importing JSON with APOC
If you have data in a JSON file, like products.json, you can use apoc.load.json to parse it. Each item in the JSON array can then be processed to create nodes and relationships.
CALL apoc.load.json('file:///products.json') YIELD value
CREATE (:Product {id: value.id, name: value.name, price: toFloat(value.price)});
Exporting Data: An Overview
Just as important as importing is exporting data from your graph. You might need to:
- Generate reports.
- Migrate data to another system.
- Perform advanced analytics outside Neo4j.
- Create backups.
We'll look at basic Cypher export and advanced APOC export.
Basic Export with Cypher
The simplest way to export data is using standard Cypher MATCH and RETURN statements. The results are displayed in the Neo4j Browser and can be copied or downloaded as CSV/JSON.
MATCH (u:User)-[:FOLLOWS]->(f:User)
RETURN u.name AS Follower, f.name AS Followed;Advanced Export with APOC
APOC offers powerful procedures to export your graph data directly to files in various formats (CSV, JSON, GraphML, etc.). These are ideal for full graph exports or specific subgraphs.
For example, to export all nodes and relationships to a CSV file:
CALL apoc.export.csv.all('full_graph_export.csv', {});Import/Export Challenge
You have a CSV file named books.csv with the columns isbn, title, author. You want to import this data into Neo4j, creating nodes with the label Book and properties for each column.
Recap: Data Movement Skills
You've learned essential skills for moving data in and out of Neo4j:
LOAD CSVis powerful for structured data.- APOC procedures extend capabilities for JSON, complex exports, and more.
- Standard Cypher
MATCHandRETURNallow simple data extraction.
Mastering these techniques is key for managing your graph data effectively!
Questions Fréquemment Posées
La leçon « Importer et exporter des données » est-elle gratuite ?
Oui — le texte complet de « Importer et exporter des données » est gratuit à lire ici sur le web. Pour la pratiquer de manière interactive (un éditeur de code intégré et un tuteur IA 24/7) et déverrouiller le reste du cours Neo4j Graph Database Fundamentals, passe à CoddyKit PRO. Le cours Neo4j Graph Database Fundamentals comprend 4 leçons au total.
Qu'est-ce que j'apprendrai dans « Importer et exporter des données » ?
Découvrez différentes méthodes pour charger des données dans Neo4j depuis des sources externes et exporter des données de graphe pour d’autres usages. Tu pratiques Neo4j Graph Database Fundamentals avec du code pratique que tu exécutes directement dans le navigateur, et un tuteur IA 24/7 répond à tes questions au fur et à mesure que tu avances dans la leçon.
Dois-je avoir de l'expérience pour commencer Neo4j Graph Database Fundamentals ?
Aucune expérience préalable n'est requise. Neo4j Graph Database Fundamentals sur CoddyKit est structuré pour les débutants jusqu'aux apprenants avancés, donc tu peux commencer ici ou depuis le début et avancer à ton rythme. Ceci est la leçon 2 sur 4.
Combien de temps prend la leçon « Importer et exporter des données » ?
La plupart des leçons CoddyKit prennent environ 5–10 minutes. Chacune est courte et interactive, tu progresses régulièrement et tu repiques exactement où tu t'es arrêté sur le web et l'app.
Peux-tu écrire et exécuter du code dans cette leçon Neo4j Graph Database Fundamentals ?
Oui. Chaque leçon Neo4j Graph Database Fundamentals inclut un éditeur de code intégré, tu écris et exécutes du vrai code directement dans ton navigateur et tu reçois des retours IA instantanés — aucune configuration locale requise.
Toutes les leçons de ce cours
- Navigateur Neo4j et outils d’administration
- Importer et exporter des données
- Stratégies de sauvegarde et de restauration
- Surveillance et journalisation dans Neo4j