Add 3 distincts commands in CYPHER to add, replace and remove all labels on a node #2073

growak opened this Issue Mar 2, 2014 · 3 comments


None yet

4 participants

growak commented Mar 2, 2014

I need to do complex update node operation in a single transactional CYPHER query sent over HTTP to the REST endpoint. I didn't find any solution to REPLACE ou REMOVE all node labels in a CYPHER statement.

  1. Add labels on a node (add labels to existing ones)
    MATCH node
    ADD node:Label1:Label2

  2. Set labels on a node (replace all existing labels)
    MATCH node
    SET node:Label1:Label2

  3. Set labels on a node (remove all labels from a node)
    MATCH node
    REMOVE node:*

jexp commented Mar 2, 2014

Afaik there is no "remove all labels" operation.

Either you send multiple queries in the same request or the same tx

MATCH (n:Foo) REMOVE n:Foo

Or you will have to list them individually.
If you know the list of labels you can "work around" it by using foreach as a conditional:

WITH n,labels(n) as labels
FOREACH (l in [l2 in labels WHERE l2="Foo"] | REMOVE n:Foo)

or CASE WHEN to create a empty or one-element list

WITH n,labels(n) as labels
FOREACH (l in (CASE WHEN "Foo" in labels THEN ["dummy"] ELSE [] END) | REMOVE n:Foo)

What is your use-case for this?

growak commented Mar 2, 2014


Thank you for the quick answer.

I want to implement an update node method.
The method is taking a node id, a set of labels and a map of properties.
I don't know the previous values of the labels or the properties and I want to replace them by new values.

As I am writing this ... I am thinking that I will have the same problem with properties !



that is an interesting work around, but when you don't know the existing labels and the possibilities are the phone book this is not a workable solution.

I foolishly tried this, thinking that the label could be dynamic.

MERGE (cg) FOREACH(label IN labels(cg) | REMOVE cg:label) SET cg:nice_label return labels(cg)

Ideally just something as simple as REPLACE cg:label1:label2 would be super useful. As it stands it looks like this will need to be multiple operations. ¯_(ツ)_/¯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment