TenTonBonton
TenTonBonton

Reputation: 119

Importing cpyherl files into Memgraph

I got a sample-data.cypherl file that looks like this:

CREATE (:Factory {id: "200", name: "Factory Alpha", location: "New York"});
CREATE (:Warehouse {id: "201", name: "Warehouse Bravo", location: "Berlin"});
CREATE (:Retailer {id: "202", name: "Retailer Charlie", location: "Tokyo"});
CREATE (:Warehouse {id: "203", name: "Warehouse Delta", location: "Sydney"});
CREATE (:Retailer {id: "204", name: "Retailer Echo", location: "Toronto"});

MATCH (u:Factory), (v:Warehouse) WHERE u.id = "200" AND v.id = "201" CREATE (u)-[:SUPPLIES]->(v);
MATCH (u:Factory), (v:Warehouse) WHERE u.id = "200" AND v.id = "203" CREATE (u)-[:SUPPLIES]->(v);
MATCH (u:Warehouse), (v:Retailer) WHERE u.id = "201" AND v.id = "202" CREATE (u)-[:DISTRIBUTES_TO]->(v);
MATCH (u:Warehouse), (v:Retailer) WHERE u.id = "201" AND v.id = "204" CREATE (u)-[:DISTRIBUTES_TO]->(v);
MATCH (u:Warehouse), (v:Retailer) WHERE u.id = "203" AND v.id = "202" CREATE (u)-[:DISTRIBUTES_TO]->(v);
MATCH (u:Warehouse), (v:Retailer) WHERE u.id = "203" AND v.id = "204" CREATE (u)-[:DISTRIBUTES_TO]->(v);

The fist batch of queries create nodes for factories, warehouses, and retailers. The second batch queries create relationships between these nodes, representing the supply chain connections. So it hoes something like this:

I know that I can simply run this as a query in Memgraph Lab, but what when I will have larger files with thousands of rows? I think that browsers have some limit when it comes to copy/pasting data info fields.

I have two instances of Memgraph for learning, native Ubuntu and one running in Docker (this is Memgraph Platform image).

How can I import cypherl files directly into them, without copy/paste method?

Upvotes: 2

Views: 48

Answers (1)

Moraltox
Moraltox

Reputation: 924

If you don't have Memgraph Lab you can run the following command on your Ubuntu installation:

mgconsole < sample-data.cypherl

This tells to mgconsole to use sample-data.cypherl as the input.

If you have Memgraph Lab go to Import & Export and import the sample-data.cypherl from there.

For Docker version you need to tun this command:

docker run -i --entrypoint=mgconsole memgraph/memgraph-platform --host HOST < sample-data.cypherl

Replace HOST with the IP address of your Docker container. You can find it out using the command docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' DOCKER-CONTAINER-ID.

And you get DOCKER-CONTAINER-ID using docker ps.

Upvotes: 1

Related Questions