Custom FindAll - SpringData/ Cypher Query


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.


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
1 Like

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