How to filter returned properties?

I have a node containing these property names: "name", "A", "B", "C", ..., "ZA", "ZB", "ZC",...

(That is, using the query match (x) where x.name="a" return keys(x) will return the result ["name", "A", "B", "C", ..., "ZA", "ZB", "ZC", ...]).

I want to return all properties whose names start with "Z"

match (x) where x.name="a" return x.ZA, x.ZB, x.ZC, ...

But since each node has a different number of Z* properties, I need a way to not specify the properties when returning.

Is there a way to do so? I read the manual for WHERE, RETURN and Filtering Query Results but there is nothing useful.

(This question is also asked on Stack Overflow)

Hi @Ooker ,

You can check the apoc.any.properties function which returns a map with a given list of node attributes (it cannot use regex, but if you know the properties of your nodes, you can search the required attributes by name). Please find below an example:

MATCH (s:Student)
UNWIND apoc.any.properties(s,["Z", "Z2"]) AS properties
RETURN properties;

Hope this helps

Hello @Ooker :slight_smile:

MATCH (x)
WHERE x.name = "a"
RETURN apoc.map.removeKeys(x, [p IN keys(x) WHERE NOT p STARTS WITH "Z"])

Regards,
Cobra