Neo4J entry notes [2]---export data as CSV

In the last section "Neo4J Introductory Notes [1] - Installation and Cypher Basic Syntax", the author mainly shared the commonly used commands for Neo4J installation. In this chapter, the author shares how to export data from Neo4j to CSV. A simple way is to call the following stored procedure.

CALL apoc.export.csv.all("database-all-data.csv", {
    
    })

But if the default configuration of Neo4j is not modified, it will report the following error.

Failed to invoke procedure `apoc.export.csv.all`: Caused by: java.lang.RuntimeException: Export to files not enabled, please set apoc.export.file.enabled=true in your apoc.conf

insert image description here
The solution is to add the following configuration in the apoc.conf configuration file and restart

apoc.export.file.enabled=true

Execute again CALL apoc.export.csv.all("database-all-data.csv", {}), see the figure below, the execution is successful.
insert image description here
The exported files can be found in the import folder under the root directory of Neo4j, such as my computer: D:\software\26.neo4j\neo4j-community-4.4.12\import The following is the exported data: if you want to query
insert image description here
a
insert image description here
specific A data set, such as the following data set:

CREATE (TheMatrix:Movie {
    
    title:'The Matrix', released:1999, tagline:'Welcome to the Real World'})
CREATE (Keanu:Person {
    
    name:'Keanu Reeves', born:1964})
CREATE (Carrie:Person {
    
    name:'Carrie-Anne Moss', born:1967})
CREATE (Laurence:Person {
    
    name:'Laurence Fishburne', born:1961})
CREATE (Hugo:Person {
    
    name:'Hugo Weaving', born:1960})
CREATE (LillyW:Person {
    
    name:'Lilly Wachowski', born:1967})
CREATE (LanaW:Person {
    
    name:'Lana Wachowski', born:1965})
CREATE (JoelS:Person {
    
    name:'Joel Silver', born:1952})
CREATE
(Keanu)-[:ACTED_IN {
    
    roles:['Neo']}]->(TheMatrix),
(Carrie)-[:ACTED_IN {
    
    roles:['Trinity']}]->(TheMatrix),
(Laurence)-[:ACTED_IN {
    
    roles:['Morpheus']}]->(TheMatrix),
(Hugo)-[:ACTED_IN {
    
    roles:['Agent Smith']}]->(TheMatrix),
(LillyW)-[:DIRECTED]->(TheMatrix),
(LanaW)-[:DIRECTED]->(TheMatrix),
(JoelS)-[:PRODUCED]->(TheMatrix);

query relationship

MATCH (person:Person)-[actedIn:ACTED_IN]->(movie:Movie)
return *

insert image description here
How to export the above relationship to a CSV file?

MATCH (person:Person)-[actedIn:ACTED_IN]->(movie:Movie)
WITH collect(DISTINCT person) AS people, collect(DISTINCT movie) AS movies, collect(actedIn) AS actedInRels
CALL apoc.export.csv.data(people + movies, actedInRels, "movies-actedIn.csv", {
    
    })
YIELD file, source, format, nodes, relationships, properties, time, rows, batchSize, batches, done, data
RETURN file, source, format, nodes, relationships, properties, time, rows, batchSize, batches, done, data

After exporting, the CSV file is as follows:
insert image description here
Reference document
https://neo4j.com/labs/apoc/4.1/export/csv/
https://neo4j.com/blog/export-csv-from-neo4j-curl-cypher-jq /#:~:text=Here%E2%80%99s%20how%20you%20do%20it%3A%20You%20can%20already,of%20a%20Cypher%20query%20to%20a%20CSV%20file.

Guess you like

Origin blog.csdn.net/chancein007/article/details/128885086