Export CSV file shows only the last record instead of all records

Hi,

I try to write an output of a query to a file.
The query below gives 123 records while in the output file only the last record is shown.
Any idea what is going wrong here ?

MATCH (panels:Panels)
WHERE panels.group = '1 - Main AC systems'
WITH collect(panels) as mainACSystemsPanels,
     panels
CALL apoc.export.csv.data(mainACSystemsPanels, [], "Panels 1 - Main AC systems.csv", {}) 
     YIELD data
RETURN mainACSystemsPanels //panels.equipmentId, panels.objectId

Output file:

_id,"_labels","depth","doorHinge","doorSort","entity","entityNumbers","entranceSide","entranceType","equipmentId","estim","final","group","height","location","make","objectId","ral","remarksPart1","remarksPart2","status","width","_start","_end","_type"
37652,":Panels","92","Unknown","Unknown","LOP Scupper Drain Pump 4","1.9.31","T/B","Unknown","862-E0011","Unknown","Unknown","1 - Main AC systems","196","1.A12.377","Schneider","28851","7035 / 7016","Unknown","Unknown","Installed","68",,,

Robert

Your ‘with’ clause includes ‘panels’, so you are collecting for each Panel node. The result is a row for each panel node with a collection containing that one panel node. As such, you are writing over the same file row by row, leaving with a file that has only the last panel node. The fix is to remove ‘panel’ from your ‘with’ clause, so you collect all panel nodes in one list, which will be passed to the export method to write all the nodes to a single file.