cancel
Showing results for 
Search instead for 
Did you mean: 

Join the community at Nodes 2022, our free virtual event on November 16 - 17.

How to filter returned properties?

Ooker
Node

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)

2 REPLIES 2

tfontanella011
Node Clone

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

Cobra
Ninja
Ninja

Hello @Ooker

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

Regards,
Cobra