Skip to content
This repository was archived by the owner on Sep 3, 2021. It is now read-only.
This repository was archived by the owner on Sep 3, 2021. It is now read-only.

How can I reuse "this" as a reference to a current node? #572

@dan-fein

Description

@dan-fein

I am using neo4j-graphql-js and in one of my cypher statement's I'm referring to "this" which is the current node. It seems that the word "this" in my first MATCH is accurate, but then when I use MATCH the second time, "this" becomes just a general keyword and defaults to an unlabeled/non-specific node (and just returns everything).

Here's the code currently. it finds any posts that are either tagging "Things" that are children of the current Thing node, or where they're tagging the current Thing node specifically.

    MATCH (this)<-[:CHILD_OF]-(t1:Thing)<-[:TAGGED]-(post:Post)
    WITH COLLECT(post) as rows
    MATCH (this)<-[:TAGGED]-(p:Post)
    WITH rows + COLLECT(p) as allRows
    UNWIND allRows as post
    RETURN count(DISTINCT post)

Any ideas how I can reuse "this" the second time? I tried sharing it after WITH COLLECT(post) as rows, like this:

WITH COLLECT(post) as rows, this

Any ideas would be appreciated, thank you in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions