SET mark: name of the passage mark as parameter

I have a request like this:

unwind {data} as row with row MERGE (p: Book {guid: row.bookGuid}) set p.name = row.name, p: Science

I want to pass the label "Science" as a parameter, since this label is not the same for all strings that I pass in {data}.

I tried below query but it throws a syntax error.

with parameter: {guid: 1, name: "testName1", label1: "Histroy"}

unwind {data} as row with row MERGE (p: Book {guid: row.bookGuid}) set p.name = row.name, p: row.label1

Any workaround?

thank

+1


source to share


3 answers


You can use APOC apoc.create.addLabels()

:

UNWIND {data} as row WITH row
MERGE (p:Book{guid:row.bookGuid})
SET p.name=row.name
CALL apoc.create.addLabels(id(p), [row.label1])

      



Another example: Using Cypher and APOC to move a property value to a label

+2


source


Yeh is not supported yet. If you want this to work, you need to do a little FOREACH hack, which you will need to do for each type of label:

unwind {data} as row with row 
FOREACH(ignoreMe IN CASE WHEN row.label = "Science" THEN [1] ELSE [] END |
    MERGE (p:Book:Science{guid:row.bookGuid}) 
    set p.name=row.name
)

FOREACH(ignoreMe IN CASE WHEN row.label = "Math" THEN [1] ELSE [] END |
    MERGE (p:Book:Math{guid:row.bookGuid}) 
    set p.name=row.name
)

      



Etc...

+1


source


I assume that you can structure your data in different ways:

(:Book {guid, name})-[:HAS_LABEL]->(:Label {name})

      

Thus, you can use the label name as a parameter in CREATE or MATCH queries. Your original query:

UNWIND {data} as row WITH row 
MERGE (p:Book {guid: row.guid})
MERGE (l:Label {name: row.label})
CREATE UNIQUE p-[:HAS_LABEL]->l
SET p.name = row.name

      

+1


source







All Articles