I have a data access function like
public IList<NodeType> GetNodesByProperties(IDictionary<string, string> properties)
which returns all neo4j nodes where all properties match.
I can't find any official way to do this kind of search through neo4jclient. I've written a function like:
public IList<NodeType> GetNodesByProperties(IDictionary<string, string> properties)
{
var baseQuery = neo4jclient.Cypher
.Match("(node:NodeType)")
.Where("true");
foreach (var tupple in properties)
baseQuery = baseQuery.AndWhere($"node.{tupple.Key} = \"{tupple.Value}\"");
var resultQuery = baseQuery
.Return(node => node.As<NodeType>());
return resultQuery.Results;
}
Which does work, but this poses an obvious Cypher injection attack risk, since the function inserts raw text directly into a Cypher query.
How can I safely search for any node properties?
.WithParam()
, but I haven't seen any solution for safely specifying a property key in a search. – Stephen Belden