rob2
( Rob)
February 8, 2021, 9:30am
1
HI
i want to list all Labels that are NOT starting with underscore ...
MATCH (nodes)
UNWIND nodes AS node
WITH node
WHERE labels(node)! =~ '_*'
RETURN labels(node)
I guess I'm running in the wrong direction .... or?
This gives me an error
Invalid input ' ': expected '=' (line 4, column 20 (offset: 65))
"WHERE labels(node)! =~ '_*'"
and ther must be an distinct somewher
can someone please help me? thanks rob
i also have to say that I'm using multilabel
so match (n) return n, Labels(n); gives me
...
["process", "_ProcessProcess", "_node", "_notdemo"]
...
["status", "_ProcessProcess", "_node", "_notdemo"]
...
["person", "_node", "_notdemo"]
...
["mail", "_node", "_notdemo"]
...
but i need only process, status, mail and person
Cobra
(Cobra)
February 8, 2021, 9:53am
2
Hello @rob2
MATCH (nodes)
UNWIND nodes AS node
WITH node
WHERE NOT labels(node) =~ '_*'
RETURN labels(node)
Regards,
Cobra
1 Like
mckenzma
(Michael McKenzie)
February 8, 2021, 2:11pm
3
I like to use db.labels()
:
CALL db.labels() YIELD label
WHERE label STARTS WITH "_"
RETURN label
This allows you to call the information stored about the database rather than querying all the nodes. So if you just want the label then this is a good fast way to get it.
3 Likes
rob2
( Rob)
February 8, 2021, 3:58pm
4
Ahh thanks, cobra
But still get the same error with your solution
MATCH (nodes)
UNWIND nodes AS node
WITH node
WHERE NOT labels(node) =~ '_*'
RETURN labels(node)
Type mismatch: expected String but was List (line 4, column 11 (offset: 55))
"WHERE NOT labels(node) =~ '_*'"
^ (at "l" of labels)
rob2
( Rob)
February 8, 2021, 4:01pm
5
MHH also have an error here
mckenzma
(Michael McKenzie)
February 8, 2021, 4:09pm
6
I edited my original response. Try STARTS WITH
. I forgot the S
Cobra
(Cobra)
February 8, 2021, 4:57pm
7
Yes, it's because labels()
returns a list of labels:
MATCH (nodes)
WITH apoc.coll.toSet(apoc.coll.flatten(labels(node))) AS labels
UNWIND labels AS label
WHERE NOT label=~ '_*'
RETURN label
Regards,
Cobra
Hello there
@mckenzma
Despite the simplicity of the problem, In terms of readability and performance best answer i ever seen in this forum.
Tested on Neo4j 4.2.3
CALL db.labels() YIELD label
WHERE NOT label STARTS WITH '_'
RETURN label
All credit to @mckenzma , except for the NOT part lol.
You should really use the answer above @rob2
I think it's not possible to do better then that. It's short and sweet.
2 Likes