Skip to main content

export_util

Module for exporting a graph database or query results in different formats. Currently, this module supports exporting database to a JSON file format and exporting query results in a CSV file format.

docs-source

TraitValue
Module typeutil
ImplementationPython
Parallelismsequential

Procedures

info

If you want to execute this algorithm on graph projections, subgraphs or portions of the graph, be sure to check out the guide on How to run a MAGE module on subgraphs.

json(path)

Input:

  • path: string ➡ Path to the JSON file containing the exported graph database.

Usage:

The path you have to provide as procedure argument depends on how you started Memgraph.

If you ran Memgraph with Docker, database will be exported to a JSON file inside the Docker container. We recommend exporting the database to the JSON file inside the /usr/lib/memgraph/query_modules directory.

You can call the procedure by running the following query:

CALL export_util.json(path);

where path is the path to the JSON file inside the /usr/lib/memgraph/query_modules directory in the running Docker container (e.g., /usr/lib/memgraph/query_modules/export.json).

csv_query(query, file_path, stream)

Input:

  • query: string ➡ A query from which the results will be saved to a CSV file.
  • file_path: string (default="") ➡ A path to the CSV file where the query results will be exported. Defaults to an empty string.
  • stream: bool (default=False) ➡ A value which determines whether a stream of query results in a CSV format will be returned.

Output:

  • file_path: string ➡ A path to the CSV file where the query results are exported. If file_path is not provided, the output will be an empty string.
  • data: string ➡ A stream of query results in a CSV format.

Usage:

The file_path you have to provide as procedure argument depends on how you started Memgraph.

If you ran Memgraph with Docker, query results will be exported to a CSV file inside the Docker container. We recommend exporting the database to the CSV file inside the /usr/lib/memgraph/query_modules directory.

You can call the procedure by running the following query:

CALL export_util.csv_query(path);

where path is the path to a CSV file inside the /usr/lib/memgraph/query_modules directory in the running Docker container (e.g., /usr/lib/memgraph/query_modules/export.csv).

Example - Exporting database to a JSON file

The image below shows the above data as a graph:

Example - Exporting query results to a CSV file

The image below shows the above data as a graph: