Reputation: 59
I have a Spring Application and in my Repository I have a query where I match Drugs and only ONE Patient but it is not defined how many drugs will be selected from the user.
Actual Cypher Query:
MATCH (p:Patient) where ID(p) = ({0})
MATCH (d:Drug) where ID(d) in [({1}),({2}),({3})]
RETURN p, d
In this query, I am matching 3 Drugs but I would like this to be like a for
statement depending on how many Drugs the user will select.
Something like that:
MATCH (p:Patient) where ID(p) = ({0})
MATCH (d:Drug) where ID(d) in [({1}),({2}),({3}),.....({10})] <-- size could be 1 or more
RETURN p, d
How can I solve this problem? Is it possible to loop in Cypher somehow? If so, how do I solve my problem?
Upvotes: 0
Views: 222
Reputation: 67044
You should be passing the values as parameters.
For example, if you use a p_id
parameter to pass the ID of the Patient
, and a d_ids
parameter to pass a collection of Drug
IDs:
MATCH (p:Patient) WHERE ID(p) = $p_id
MATCH (d:Drug) WHERE ID(d) IN $d_ids
RETURN p, d
Upvotes: 2