0

Is it possible to build a multigraph (interconnected multilayer network) with Memgraph?? Or will it be possible in near future?

MPesi
  • 212
  • 8

1 Answers1

0

If you are speaking of a multigraph as a graph that is permitted to have multiple relationships, that is relationships that have the same end nodes, that is possible in Memgraph. You can create the same nodes and relationships as many times as you want, and that's why you have to be careful when to create and when to merge a node/relationship you are importing to your database. There are two ways of having multiple relationships between the same start and end nodes. First, you can create relationships of different type and second, you can create relationships of the same type. For example, let's say you have two nodes labeled as Person (Anna and James) and two types of relationships between them (LOVES, IS_MARRIED_TO). Then you can create that with:

CREATE (:Person {name: "Anna"})-[:LOVES]->(:Person {name: "James"}); MATCH (n:Person {name: "Anna"}), (m:Person {name: "James"}) CREATE (n)-[:IS_MARRIED_TO]->(m);

Now let's say you want to create another relationship from Anna to James of type LOVES. You can do that with:

MATCH (n:Person {name: "Anna"}), (m:Person {name: "James"}) CREATE (n)-[:LOVES]->(m);

Since I used CREATE and not MERGE, another relationship of type LOVES will be created. To verify that:

MATCH ()-[r:LOVES]->() RETURN count(r);

and you get 2, since there are 2 relationships of type LOVES.

MPesi
  • 212
  • 8