31m
https://community.neo4j.com/t/dynamic-relationship-by-importing-files-from-json/32996?u=poojanarayan0805
I have 3 JSON files "DataStore.json", "Network.json", "VMDetails.json"
I wanted to create nodes and relationships dynamically by importing data
from JSON using apoc.load.json function.
I used the below-mentioned queries
To Create DataStore nodes
CALL apoc.load.json("file:///DataStore.json") YIELD value AS data
MERGE (d:UserD{DataStore: data.DataStore})
SET d.Name = data.Name,
d.Type = data.Type,
d.Capacity = data.Capacity,
d.Free = data.Free
To create Network nodes
CALL apoc.load.json("file:///Network.json") YIELD value AS net
MERGE(n:UserN{Network:net.Network})
SET n.Name =net.Name
Everything works as expected till here
I wanted to create a relationship with DataStore node and VM node and
another relationship with Network node and VM node while creating VM node
I used the below-mentioned query
CALL apoc.load.json("file:///VmDetails.json") YIELD value AS vm
MERGE(n:UserN{Network:vm.Network})
MERGE(d:UserD{DataStore:vm.DataStore})
MERGE(v:UserV{vmName:vm.vmName})
SET v.CPU= vm.CPU,
v.ConnectionState = vm.ConnectionState,
v.DataStore = vm.DataStore,
v.Hostname = vm.Hostname,
v.InstanceUuid = vm.InstanceUuid,
v.IpAddress = vm.IpAddress,
v.Network = vm.Network,
v.NumEthernetCards = vm.NumEthernetCards,
v.NumVirtualDisks = vm.NumVirtualDisks,
v.OverallStatus = vm.OverallStatus,
v.PowerState = vm.PowerState,
v.RAM = vm.RAM,
v.Uuid = vm.Uuid
MERGE (n)-[:connected]->(v)
MERGE (v)-[:related]->(d)
This query is creating new DataStore and Network nodes instead of creating
a relationship with the existing nodes. Can anyone tell me where I am going
wrong? It would be very helpful. Thanks in advance