cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How many degrees of nodes can a relationship be set?

Totally new to graphs database. So my question is totally newb.
Could a node relationship be remembered as a long chain of nodes?
For example in the IT network demo.
I have a PC(a) who have software(b) with version(c) that needs to update to(d)
so my graph will be (a)--(b)--(c)--(d)
I would like to keep 1 software name and split out the version. So my software version relationship would be
(:PC {name:'PC1'})<--(:Software {name:'MS Word'})-->(:Version {name:2001})-->(:Update {name:'SP2'})
(:PC {name:'PC2'})<--(:Software {name:'MS Word'})-->(:Version {name:2012})-->(:Update {name:'SP3'})
I want to have 2 PCs in example both running MS Word.
PC1 has MS Word version 2001 and PC2 has MS Word 2012.
The question is then can I use this graph to differentiate which version relationship of node (b) even though there are two relationship links to two node (c)
Otherwise do I just have software nodes with different names rather than having version type separate. like (:Software {name:'MS Word 2001'})-->(:Update {name:'SP2'})

2 REPLIES 2

Hi Alex!

Welcome to the world of LPGs (labeled property graphs). I remember having similar episodes of figuring out modeling questions like this when I started.

I will lead with this: if there is some direct relationship between information that you want to query for, then the cleanest way to do this is to make them directly related. Through each relationship to a different node, you are potentially introducing a new degree of freedom, and you will need to plan how you will incorporate the required context in order to fetch relevant information through your queries.

In the model you provided, I suggest that the node labels "Version" and "Update" might actually be additional properties under "Software"-labeled nodes. If you want to keep your current relationships/nodes, you could create a new node label called "SoftwareVersion". In this approach, your data might be entered like this:

(:PC {name:'PC1'})-[:SW_INSTALLED]->(:SoftwareVersion {name:'MS Word', version:2001, update:'SP2'})
(:PC {name:'PC2'})-[:SW_INSTALLED]->(:SoftwareVersion {name:'MS Word', version:2012, update:'SP3'})

Now, if you want to keep track of time variants in your graph (e.g., past, current, future installed software versions), you might go further and add:

(:PC {name:'PC1'})-[:SW_INSTALLED {status:'current', installed_date:'2020-11-30', installer:'walex'}]->(:SoftwareVersion {name:'MS Word', version:2001, update:'SP2'})
(:PC {name:'PC1'})-[:SW_INSTALLED {status:'planned', installed_date:'2021-06-06'}]->(:SoftwareVersion {name:'MS Word', version:2012, update:'SP3'})
(:PC {name:'PC2'})-[:SW_INSTALLED {status:'current', installed_date:'2020-04-24', installer:'walex'}]->(:SoftwareVersion {name:'MS Word', version:2012, update:'SP3'})

Generally speaking, LPGs provide such flexible data models, that it often helps to first consider how you intend to query your graphs for information. Consider what knowledge you anticipate to get out of your graph, and implement your nodes and relationships to support the queries needed. Each and every node and relationship entered into the graph is atomic. Any sort of contextual information MUST be baked into your model so that your queries have the breadcrumbs they need at each step of traversal.

Also what I found helpful when starting out with LPGs was considering what questions I could answer with a given implementation approach. With your original approach, I can't directly ask the question you posed, which I will re-state as: What software version/updates are installed on which computers on the network? But I can ask it: What versions exist for a particular software product? Am I interested in the answer to this question? If not, does it indicate some superfluous modeling decisions?

This feedback loop will help you refine your graph model over time:

  • what questions can my graph currently answer?
  • what information can be added to and where in my graph in order to answer particular questions?

Wish you all the best!
Ken

Thanks for the well thought out explanation. I think I understand it better now.

Thank you!