I'm a novice with Memgraph and was attempting to initialize a database by importing a .cypherl file in Memgraph Lab. Individual nodes are imported successfully, the relationships seem to reference nodes without any labels. When I directly execute the same queries in the Memgraph Lab's query editor, everything works perfectly. What could be the reason for this discrepancy?
Here's my code:
CREATE (a:Article {title: 'On Writing', author: 'Hemingway'})
CREATE (m:Magazine {title: 'Edition 1'})
CREATE (m)-[:MAGAZINE_OF]->(a)
CREATE (v0:Volume {title: 'V1', issues: 1})
CREATE (v0)-[:VOLUME_OF]->(m)
CREATE (v1:Volume {title: 'V2', issues: 2});
If I use Memgraph Lab's Import & Export UI to import this file I would expect to get a database with appropriately linked nodes and a schema identical to what's achieved when the queries are run directly in the query editor.
The
.cypherlfiles are processed in Memgraph Lab so that each line is executed as a separate transaction. When the lineCREATE (m)-[:MAGAZINE_OF]->(a)is executed, it ends up creating a relationship between two nodes with no labels.To get around this issue you can structure your
.cypherlfile to first match any previously defined nodes or relationships before creating new ones:When you import this file, you should see the expected dataset in Memgraph Lab.
If you export a
.cypherlfile from your existing dataset in Memgraph, navigate to the Import & Export tab. The exported.cypherlfile might look somewhat different but will be structured in a way to ensure correct importing.Before importing, the
.cypherlfile initially creates indexes and removes them in the end. Importing will first define all nodes and then execute the necessary matching based on generated ids.