Raza Ul Haq
Raza Ul Haq

Reputation: 344

neo4j-nodes label with MERGE

I have created graph using MERGE to avoid repetition, following is the query

LOAD CSV WITH HEADERS 
     FROM "file:///C:/Users/username/Desktop/file.csv" 
     AS network
MERGE (sourceNode {id:network.node1})
MERGE (destNode {id:network.node2})
WITH sourceNode, 
     destNode, 
     network

It doesn't assign labels to nodes but I need labels to query graph. Is there any way to assign labels to nodes? Thanks in advance.

Upvotes: 0

Views: 502

Answers (2)

techie95
techie95

Reputation: 515

You seemed to miss the variables which are supposed to be assigned to a node before the labels.This way your nodes will be assigned labels and you can use their respective variables for operations on them. I've modified the query. Hope this helps!

LOAD CSV WITH HEADERS 
 FROM "file:///C:/Users/username/Desktop/file.csv" 
 AS network
MERGE (n:sourceNode {id:network.node1})
MERGE (m:destNode {id:network.node2})
WITH n,m,network

Upvotes: 1

InverseFalcon
InverseFalcon

Reputation: 30407

You may want to review the developer guide. Here's how to create a node with a label. However, if you want to set a label dynamically, such as from a CSV, then you will need to use APOC Procedures for this, as it is not supported natively by Cypher.

Upvotes: 1

Related Questions