Search code examples
neo4jcypherneo4j-apoc

Can't filter aggregated Neo4j query with property


I have a query summarize nodes and relationships as groups, and i cant make it get filtered by property. Query below:

CALL apoc.nodes.group(['*'],["workspace"]) YIELD nodes, relationships
Unwind nodes as node
unwind relationships as rel
WITH coalesce(node) as result, rel
return result

Result shows that Result Image

But I can't access with result.workspace, it shows me [] empty arrays. I want to be able to filter with result.workspace = '100'

EDIT: I have added new screenshot which showing result of query. I'm trying to achieve get only gray ones which have property 'workspace':'100' (It can be for example '99' as my query) and not the others like greens which 'workspace':'99' or with the different properties.

Image

EDIT2: With this query it returns nothing

CALL apoc.nodes.group(['*'],['workspace']) YIELD nodes UNWIND nodes as node WITH node WHERE node.workspace = '100' RETURN node

Image after query

PROBLEM SOLVED with query below:

CALL apoc.nodes.group(['*'],['workspace']) YIELD nodes,relationships UNWIND nodes as node UNWIND relationships as rel WITH node, rel WHERE apoc.any.properties(node).workspace = '100' RETURN node,rel

apoc.any.properties() works on virtual nodes like they are real nodes.


Solution

  • [UPDATED]

    This will return only the group nodes that have the workspace property value '100':

    CALL apoc.nodes.group(['*'],["workspace"]) YIELD nodes
    UNWIND nodes AS node
    WITH node
    WHERE apoc.any.property(node, 'workspace') = '100'
    RETURN node
    

    NOTE: You have to use the apoc.any.property function to get a property value from a virtual node.