简体   繁体   中英

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

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) "

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM