How to pass a parameter as a relationship for part of a cypher query for neo4j using neography

301 Views Asked by At

I want to pass to my neography query using cypher a relationship, and have the query execute on that relationship.

I currently get an error:

query_response = @neo.execute_query("MATCH   (fromNode)-[{relationship}]->(toNode) 
                                    WHERE   fromNode.bot_client_id = {bot_client_id} AND toNode.epoch_utc_i > {fromTime} AND toNode.epoch_utc_i < {toTime} 

                                    RETURN  toNode.value
                                    LIMIT   {limit}", 
                                    {
                                        :fromTime => fromTime, :toTime => toTime, :bot_client_id => @bot_client_id, 
                                        :limit => limit, :relationship => relationship.to_sym
                                    }
                                )  



Neography::SyntaxException: Parameter maps cannot be used in MATCH patterns (use a literal map instead, eg. "{id: {param}.id}") (line 1, column 21 (offset: 20))
    "MATCH   (fromNode)-[{relationship}]->(toNode) "
1

There are 1 best solutions below

0
On

Since {relationship} is a map with only a single property, you can do one of the following. Let's say the map is {x: 123}.

  1. You can just use the property from the map in your MATCH pattern:

    MATCH (fromNode)-[ {x: {relationship}.x} ]->(toNode)
    
  2. Instead of using a map, you can just pass the value of x as a parameter. In this example, I assume that you have replaced {relationship} with {x}:

    MATCH (fromNode)-[ {x: {x}} ]->(toNode)
    

Note: the recent versions of neo4j have deprecated the {x} syntax, and now prefer $x.