Cypher query to dynamically match a parameter in apoc call
I am using the query of the following structure
MATCH path=((:Start)-[:NEXT*..100]->(n))
WHERE ALL(mnode IN nodes(path)
WHERE mnode.minimum <= $data[mnode.checkagainst])
where data
is something like {checkparam1: 24}
. For me it is: the name of the parameter with which I want to check the minimum number of residents in node.
Everything works fine, however when I create apoc
stuff like
MATCH path=((:Start)-[:NEXT*..100]->(n))
WHERE ALL(mnode IN nodes(path)
WHERE mnode.minimum <= apoc.date.toYear($data[mnode.checkagainst]))
he tells me
Failed to invoke function `apoc.date.toYears`: Caused by: java.lang.NullPointerException
I suspect I cannot rely on the "request memory information" inside the apoc call, because when I manually fill in the value mnode.checkagainst
like
MATCH path=((:Start)-[:NEXT*..100]->(n))
WHERE ALL(mnode IN nodes(path)
WHERE mnode.minimum <= apoc.date.toYear($data['checkparam1']))
the apoc call works. Not sure if this is the intended behavior?
Any suggestions for a workaround?
source to share
The call apoc.date.toYear($data[mnode.checkagainst])
will result in this error if the mnode
property is missing checkagainst
.
The following (partial) request should only contain paths where all nodes have the property checkagainst
(and pass the test <=
):
MATCH path=((:Start)-[:NEXT*..100]->(n))
WHERE ALL(mnode IN nodes(path)
WHERE
mnode.checkagainst IS NOT NULL &&
mnode.minimum <= apoc.date.toYears($data[mnode.checkagainst]))
source to share