
Data is exported as Cypher statements to the given file.

It is possible to choose between three export formats:

* `neo4j-shell`: for Neo4j Shell and partly `apoc.cypher.runFile`
* `cypher-shell`: for Cypher shell
* `plain`: doesn't output begin / commit / await just plain Cypher

To change the export format, you have to set it on the config params like `{format : "cypher-shell"}`.

By default the format is `neo4j-shell`.

It is possible to choose between four cypher export formats:
To change the cypher export format, you have to set it on the config params like `{cypherFormat: "updateAll"}`

* `create`: all CREATE
* `updateAll`: MERGE instead of CREATE
* `addStructure`: MATCH for nodes + MERGE for rels
* `updateStructure`: MERGE + MATCH for nodes and rels

Format and cypherFormat can be used both in the same query giving you complete control over the exact export format:

[source,cypher]
----
call apoc.export.cypher.query(
"MATCH (p1:Person)-[r:KNOWS]->(p2:Person) RETURN p1,r,p2",
"/tmp/friendships.cypher", 
{format:'plain',cypherFormat:'updateStructure'})`
----

// tag::export.cypher[]
`YIELD file, source, format, nodes, relationships, properties, time`
[cols="1m,5"]
|===
| apoc.export.cypher.all(file,config) | exports whole database incl. indexes as Cypher statements to the provided file
| apoc.export.cypher.data(nodes,rels,file,config) | exports given nodes and relationships incl. indexes as Cypher statements to the provided file
| apoc.export.cypher.graph(graph,file,config) | exports given graph object incl. indexes as Cypher statements to the provided file
| apoc.export.cypher.query(query,file,config) | exports nodes and relationships from the Cypher statement incl. indexes as Cypher statements to the provided file
| apoc.export.cypher.schema(file,config) | exports all schema indexes and constraints to cypher
|===
// end::export.cypher[]
== Examples

.exportAll (neo4j-shell format)

[source,cypher]
----
CALL apoc.export.cypher.all({fileName},{config})
----
Result:
[source,cypher]
----
begin
CREATE (:`Foo`:`UNIQUE IMPORT LABEL` {`name`:"foo", `UNIQUE IMPORT ID`:0});
CREATE (:`Bar` {`name`:"bar", `age`:42});
CREATE (:`Bar`:`UNIQUE IMPORT LABEL` {`age`:12, `UNIQUE IMPORT ID`:2});
commit
begin
CREATE INDEX ON :`Foo`(`name`);
CREATE CONSTRAINT ON (node:`Bar`) ASSERT node.`name` IS UNIQUE;
CREATE CONSTRAINT ON (node:`UNIQUE IMPORT LABEL`) ASSERT node.`UNIQUE IMPORT ID` IS UNIQUE;
commit
schema await
begin
MATCH (n1:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`:0}), (n2:`Bar`{`name`:"bar"}) CREATE (n1)-[:`KNOWS`]->(n2);
commit
begin
MATCH (n:`UNIQUE IMPORT LABEL`)  WITH n LIMIT 20000 REMOVE n:`UNIQUE IMPORT LABEL` REMOVE n.`UNIQUE IMPORT ID`;
commit
begin
DROP CONSTRAINT ON (node:`UNIQUE IMPORT LABEL`) ASSERT node.`UNIQUE IMPORT ID` IS UNIQUE;
commit
----
.exportSchema (neo4j-shell format)
[source,cypher]
----
CALL apoc.export.cypher.schema({fileName},{config})
----
Result:
[source,cypher]
----
begin
CREATE INDEX ON :`Foo`(`name`);
CREATE CONSTRAINT ON (node:`Bar`) ASSERT node.`name` IS UNIQUE;
commit
schema await
----
