Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
06-29-2021 07:23 PM
Hello neo4j community,
I'm looking for help on how to create multiple nodes with 1 node in the center with labels and with 8 others nodes surrounding it with labels and relationship labels. I was able to create the nodes but I'm lost on how to create the relationships for all of them. Please help!
Thank you,
Dar
Here is what I have...
Create (a: DeviceID {Tag:"C1000-8T-2G-L"}), (b: FastEthernetPorts {Tag:"8"}), (c: Uplink {Tag:"SFP/RJ-45 combo"}), (d: Power {Tag:"None"}), (e: Fanless {Tag:"Yes"}), (f: Width {Tag:"10.56 in"}), (g: Depth {Tag:"7.28 in"}), (h: Height {Tag:"1.73 in"}), (I: Weight {Tag:"1.8"}) return a, b, c, d, e, f, g, h, i
These create nodes "a" through "i" for me. Please show me and help me to link them with labels. I would like the "C1000-8T-2G-L" to be in the center and the other nodes surround it with link and labels.
Thank you
07-01-2021 12:45 PM
You should have extend the code (just before "Return" or instead of return) with
create (a)-->(b)
create (a)-->(c)
create (a)-->(d)
create (a)-->(e)
create (a)-->(f)
create (a)-->(g)
create (a)-->(h)
create (a)-->(i)
But actually it is not "good" to create a node just to store a value. Quantifications are property of the main node. How probable is it that a second device has a width of 10.56? You will have a lot of nodes splitted into unconnected graphs.
Also set numerical properties as numerical, not string. How would you query
"all Router with more than 6 ports"
if portsCount is a string?
Design proposition:
Create (a:Device{
id:"C1000-8T-2G-L",
portsType:"FastEthernet",
portsCount:8,
uplink:"SFP/RJ-45 combo",
power:"None",
fan:"None",
width:10.56,
depth:7.28,
height:1.73,
weight:1.8
})
Create (b:DeviceType{name:"Router"})
Create (c:DeviceSubType{Name:"FastEthernetRouter"})
Create (a)-[:is_a]->(c)
Create (c)-[:is_subtype_of]->(b)
If you need frequent query on some properties, you can index them to accelerate the queries.
Hope it helps. Cheers.
07-03-2021 06:50 AM
Hi Dare,
the easiest way would have been to create the relation within the code given before. So was my answer.
If you want to do this, you will have to delete all nodes before (I think your database is only a sandbox and no production).
If you want to create the relations afterward, you will to ensure to access the right nodes to create the right relation (based on your former nodes creation):
Match (x:DeviceID) Where x.Tag="C1000-8T-2G-L"
Match (y:FastEthernetPorts) where y.Tag="8"
Merge (x)-[r:HAS]->(y)
(Actually you should have at least one property on each node which is as unique indexed. If not, you could create more than one node with the Tag "C1000-8T-2G-L". And the match above will return more than one node of label DevideID)
You will have to make this "match and use" for each nodes of the relation you want to create.
Other way:
delete:
Match (n) detach delete (n)
and recreate
Create
(a:DeviceID {Tag:"C1000-8T-2G-L"}),
(b:FastEthernetPorts {Tag:"8"}),
(c:Uplink {Tag:"SFP/RJ-45 combo"}),
(d:Power {Tag:"None"}),
(e:Fanless {Tag:"Yes"}),
(f:Width {Tag:"10.56 in"}),
(g:Depth {Tag:"7.28 in"}),
(h:Height {Tag:"1.73 in"}),
(i:Weight {Tag:"1.8"})
create (a)-[:FastEthernetPorts]->(b)
create (a)-[:Uplink]->(c)
... and so on
May be you will discover that this data design makes not a lof of sense. But I already told. ou have to find your way.
Wish you success.
Cheers
Benoit
All the sessions of the conference are now available online