Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
05-14-2020 01:42 AM
I am using py2neo
to run a Cypher query in Python. Currently, I am passing the values of $user_id
and $name
.
query = "MATCH (user:User{id:$user_id, name: $name}) MATCH (user)-[rout]->() WITH user, collect(DISTINCT {relationship: type(rout), node: endNode(rout)}) AS extended_info RETURN { user: user, extended_info: extended_info } AS result"
graph.run(query, parameters= {"user_id": 1, "name": "Vivek"}).data()
Instead of just passing the values, I want to pass a dictionary of key and value. Something like this:
{id:1, name: "Vivek"}
And use it directly in the query. This will provide me with the flexibility to write a single query for filtering for one or multiple properties.
query = "MATCH (user:User{$params}) MATCH (user)-[rout]->() WITH user, collect(DISTINCT {relationship: type(rout), node: endNode(rout)}) AS extended_info RETURN { user: user, extended_info: extended_info } AS result"
graph.run(query, parameters= {id:1, name: "Vivek"}).data()
Is there a way to do it using py2neo
? Or is there any other way to write a single query for a match query?
06-26-2020 12:48 AM
Hi @vmaskara,
Welcome to the community!
This is definitely resolved in py2neo 5.0b1. I believe that there's been a syntax change between versions.
$ pip intall py2neo==5.0b1
(for people of the future find the latest version here: https://github.com/technige/py2neo)
Have you tried upgrading? Try this and check to see if your queries are working as expected. Hopefully this does the trick.
All the best
02-22-2021 08:40 AM
In the latest version this is achieved with
query = "MATCH (user:User $params ) MATCH (user)-[rout]->() WITH user, collect(DISTINCT {relationship: type(rout), node: endNode(rout)}) AS extended_info RETURN { user: user, extended_info: extended_info } AS result"
graph.run(query, params= {id:1, name: "Vivek"})
All the sessions of the conference are now available online