Search code examples
neo4jgraph-theory

How to store graphs in a graph database?


I'm currently working on a project where we want to store sets of graphs in a graph database. For this purpose im using Neo4J and I can imagine two different solutions.

  1. Put the nodes as the nodes into the database and the edges as the edges. Every edge and every node has a property graph_id, which indicates for nodes and edges to which graph they belong (trivial).

  2. create three different labels of Nodes. The first label is Node, the second Edge and the third Graph. Now every node can be stored as Node, every edge as edge-Node and every edge and node belonging to a graph is connected to a graph node. ( the Neo4J documentation suggests to create labels for the different kinds of elements in the database )

Which solution would you prefer?


Solution

  • I think you are misreading the docs. They mean that different kinds of nodes should have different labels and different kinds of edges should have different labels. If you make everything, including edges into "nodes" then you will not be able to apply the library's implementations of graph theory algorithms.

    Option 1 is the way to go.