Search code examples
neo4jexport-to-csvgraph-databasesdump

Convert Neo4j-Database-Dump Into CSV-File Without Neo4j-Enterprise-Server


How are you supposed to convert Neo4j-Database-Dumps into CSV-Files?

I've created a Neo4j-Docker-container
Which is created from Neo4j Community Edition (5.6.0).
Read the Neo4j-Docs's Export-to-CSV.
Got a Neo4j-Database-Dump from ICIJ's Offshore-Leaks-Database
On their GitHub OffshoreLeaks-Data-Packages.
Imported on the Neo4j-Docker-container's Neo4j-Community-Server.

I'm looking for ways to export without needing to sign-up or purchase Neo4j.
I just want the data to be importable to other databases and services.
What are some ways you've come up with exporting the data?

I cannot export the database as-is, because
Neo4j only allows 1 User-Database for Community-Edition-Installations.
So their docs on Export-2-CSV don't work as-is here.


Solution

  • The only way I've gotten this to work is this.

    Steps:

    1. Get Graph Database Data
    2. Rename to dump extension as needed
    3. Create Neo4j-Docker-Container
       docker run -d \
          -p 7474:7474 -p 7687:7687 \
          -e apoc.export.file.enabled=true \
          -e apoc.import.file.enabled=true \
          -e apoc.import.file.use_neo4j_config=true \
          -e NEO4J_PLUGINS=\[\"apoc\"\] \
          neo4j
      
    4. Create the Neo4j-Dumps Directory
      1. winpty docker exec -it [neo4j_container] sh
      2. mkdir /var/lib/neo4j/data/dumps
    5. Import Data into Neo4j-Container
      docker cp [filename] [neo4j-container]:/var/lib/neo4j/data/dumps/
      
    6. Create an apoc.conf that allows Neo4j-Dumps
      1. winpty docker exec -it [neo4j_container] sh
      2. Create apoc.conf
        • touch /var/lib/neo4j/conf/apoc.conf
      3. Add/Edit apoc.conf
        apoc.export.file.enabled=true
        apoc.import.file.enabled=true
        apoc.import.file.use_neo4j_config=true
        dbms.security.procedures.unrestricted=apoc.*
        
        • Needed if commands not working
      4. Restart Neo4j-Container to take affect
    7. Restore Database Dump
      bin/neo4j-admin database load [filename (no extension)] --overwrite-destination
      
    8. Migrate Database Dump to Neo4j v5.X.X
      bin/neo4j-admin database migrate [filename (no extension)] --force-btree-indexes-to-range
      
    9. Reassign the single User-Database that Neo4j allows
      1. Edit neo4j.conf
      2. Add / Uncomment-Edit
        • The filename decides the database name
        initial.dbms.default_database=[filename (no extension)]
        
      3. Restart Neo4j-Container to take affect
    10. Rename the Neo4j-Dump file as neo4j.dump
      • This is because only the Neo4j-Database is allowed APOC commands
      • Either edit the filename or readd
    11. Restore Database Dump
      bin/neo4j-admin database load neo4j --overwrite-destination
      
    12. Migrate Database Dump to Neo4j v5.X.X
      bin/neo4j-admin database migrate neo4j --force-btree-indexes-to-range
      
    13. Reassign the single User-Database that Neo4j allows
      1. Edit neo4j.conf
      2. Add / Uncomment-Edit
        initial.dbms.default_database=neo4j
        
      3. Restart Neo4j-Container to take affect
    14. Restore Database Dump
      CALL apoc.export.csv.all("filename.csv", {})
      
      1. Use the Neo4j Studio (Website)
      2. Use Command-Line
        1. Shell into the Neo4j-Container
        2. /var/lib/neo4j/bin/neo4j command
    15. Save neo4j.csv from /var/lib/neo4j/import/neo4j.csv