Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
02-08-2021 01:30 AM
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
Solved! Go to Solution.
02-08-2021 06:11 AM
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.
02-08-2021 01:53 AM
Hello @rob2
MATCH (nodes)
UNWIND nodes AS node
WITH node
WHERE NOT labels(node) =~ '_*'
RETURN labels(node)
Regards,
Cobra
02-08-2021 06:11 AM
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.
02-08-2021 08:01 AM
MHH also have an error here
02-08-2021 08:09 AM
I edited my original response. Try STARTS WITH
. I forgot the S
02-08-2021 07:58 AM
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)
02-08-2021 08:57 AM
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
02-08-2021 10:39 AM
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.
All the sessions of the conference are now available online