cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Custom FindAll - SpringData/ Cypher Query

Hello,

Assuming I have Surname Unique ( is an Example... )

  @Query("MATCH (n:User:`$surname`) return n ")
  Flux<UserEntity> customFindAll(@Param("surname") String surname);

<- This query doesnt work in spring-data otherwise was too easy of course...

How can I write a query with a dynamic surname in input @Param ?
in this case I am trying to make a customFindAll -> ( Please note that I don't need the findAll for Id , but another parameter, like in this case the surname.. )

Thank you as always for your time.

Andrea.

1 ACCEPTED SOLUTION

The query won't work in Neo4j itself either. Labels are a statically compiled part of the Query, one cannot use parameters for them.

In case you mistake Labels with properties, the following query would work:

@Query("MATCH (n:User {userName: $surname}) return n ")

Gives you all nodes with a label User and a property userName equals to your parameter.

In case you did indeed store usernames as additional labels, I would go with

MATCH (n:User) WHERE $surname IN labels(n) RETURN n

View solution in original post

2 REPLIES 2

The query won't work in Neo4j itself either. Labels are a statically compiled part of the Query, one cannot use parameters for them.

In case you mistake Labels with properties, the following query would work:

@Query("MATCH (n:User {userName: $surname}) return n ")

Gives you all nodes with a label User and a property userName equals to your parameter.

In case you did indeed store usernames as additional labels, I would go with

MATCH (n:User) WHERE $surname IN labels(n) RETURN n

great thank you for your help and feedback @michael.simons1

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

All the sessions of the conference are now available online