cancel
Showing results for 
Search instead for 
Did you mean: 

How to export relationships into different files than nodes themselves using APOC?

lingvisa
Graph Fellow

``apoc.export.csv.all apoc.export.csv.all(file :: STRING?, config :: MAP?) :: (file :: STRING?, source :: STRING?, format :: STRING?, nodes :: INTEGER?, relationships :: INTEGER?, properties :: INTEGER?, time :: INTEGER?, rows :: INTEGER?, batchSize :: INTEGER?, batches :: INTEGER?, done :: BOOLEAN?, data :: STRING?) apoc.export.csv.all(file,config) - exports whole database as csv to the provided file

This function signature is hard to read for the 'config' argument.

CALL apoc.export.csv.all("movies.csv", {})

Is there a way to configure the 'relationships' to be imported into a different file than nodes? or this is not possible?

1 REPLY 1

robert_quinn
Node Clone

check out apoc.export.csv.data it exports specified nodes and relationships as csv so you can export them to different files at the expense of 2 separate passes.

MATCH (n)--()
WITH collect(DISTINCT n) AS ns
CALL apoc.export.csv.data(ns, , "nodes.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

MATCH ()-[rel]-()
WITH collect(rel) AS rels
CALL apoc.export.csv.data(, rels, "rels.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

I'm sure there's something more elegant but this works