这是到目前为止使用的代码:
CREATE (router1:Router {name:'router1', defaultgw:'192.168.123.1'})
CREATE (network1:Network {name:'network1', cidr:'192.168.123.0/24'})
CREATE (server1:Server {hostname:'server1', ip:'192.168.123.7'})
CREATE (server2:Server {hostname:'server2', ip:'192.168.123.9'})
CREATE
(router1)-[:CONNECTED_TO {}]->(network1),
(network1)-[:CONNECTED_TO {}]->(server1),
(network1)-[:CONNECTED_TO {}]->(server2)
WITH router1 AS r
MATCH (r)-[:CONNECTED_TO]->(n)-[:CONNECTED_TO]->(s) RETURN r,n,s
;
是否有一种方法可以表示路由器和网络之间使用的子网以及服务器和相关网络之间的链接上服务器的IP,而不是适当但毫无意义的CONNECTED_TO
?
我试图将关系定义为:
CREATE (router1)-[:CONNECTED_TO {'192.168.123.0/24'}]->(network1)
or
CREATE (router1)-[:CONNECTED_TO {network1.cidr}]->(network1)
没有成功。甚至有可能吗?
非常感谢您的帮助
答案 0 :(得分:1)
[编辑]
每个属性都需要一个名称。例如,cidr
:
CREATE (router1)-[:CONNECTED_TO {cidr: '192.168.123.0/24'}]->(network1)
这是一个完整的查询:
CREATE (router1:Router {name:'router1', defaultgw:'192.168.123.1'})
CREATE (network1:Network {name:'network1', cidr:'192.168.123.0/24'})
CREATE (server1:Server {hostname:'server1', ip:'192.168.123.7'})
CREATE (server2:Server {hostname:'server2', ip:'192.168.123.9'})
CREATE
(router1)-[:CONNECTED_TO {cidr: '192.168.123.0/24'}]->(network1),
(network1)-[:CONNECTED_TO {ip:'192.168.123.7'}]->(server1),
(network1)-[:CONNECTED_TO {ip:'192.168.123.9'}]->(server2)
WITH router1 AS r
MATCH (r)-[:CONNECTED_TO]->(n)-[:CONNECTED_TO]->(s) RETURN r,n,s
;
但是将这个属性添加到关系中会导致将该属性存储在两个位置-这可能是浪费的,并且如果需要更改属性值,则需要额外的精力才能在多个位置执行更新。我建议将属性仅放在一个位置,具体决定取决于您所有用例的需要。