Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
05-20-2019 03:56 PM
I have a graph of Restaurants that are located in different plazas
I'm using the following statement but it's returning all the properties from Plaza and Restaurant
MATCH r=(p:Plaza)-[:in_plaza]->(rs:Restaurant)
WITH COLLECT(r) AS rs
CALL apoc.convert.toTree(rs) yield value
RETURN value
How I can only return certain properties instead of the whole object property same as when i do
MATCH (p:Plaza)-[:in_plaza]->(rs:Restaurant) return p.name as plaza, rs.name as restaurant only returns these two properties
Solved! Go to Solution.
05-21-2019 10:03 AM
Ah ok, its possible that this will do it:
nodes: map of list, a key is the name of the label, value is a list of properties that can be included or excluded. e.g
nodes:{LABEL:<[prop1, prop2]/[-prop1, -prop2]>}
So:
MATCH r=(p:Plaza)-[:in_plaza]->(rs:Restaurant)
WITH COLLECT(r) AS rs
CALL apoc.convert.toTree(rs, {
nodes: {Plaza: ['name'], Restaurant: ['name']}
}) yield value
RETURN value
might do it no promises!
05-21-2019 05:15 AM
Do you know what version of APOC you are using? I couldn't find the documentation for apoc.convert.toTree
05-21-2019 08:51 AM
i'm using version 3.5.0.3, it's true i can't find the documentation either, but there are multiple discussions on stack overflow with examples using it. it's documented in 3.3 https://neo4j-contrib.github.io/neo4j-apoc-procedures/index33.html#_from_tojson
below is a snapshot of the results i'm getting.
I'm thinking that if there's a way to filter the properties before using this function
05-21-2019 10:03 AM
Ah ok, its possible that this will do it:
nodes: map of list, a key is the name of the label, value is a list of properties that can be included or excluded. e.g
nodes:{LABEL:<[prop1, prop2]/[-prop1, -prop2]>}
So:
MATCH r=(p:Plaza)-[:in_plaza]->(rs:Restaurant)
WITH COLLECT(r) AS rs
CALL apoc.convert.toTree(rs, {
nodes: {Plaza: ['name'], Restaurant: ['name']}
}) yield value
RETURN value
might do it no promises!
05-21-2019 10:29 AM
Thanks, It worked, however, i had to pass the second a required second parameter as boolean (lowercase/uppercase relationship names)
MATCH r=(p:Plaza)-[:in_plaza]->(rs:Restaurant) WITH COLLECT(r) AS rs CALL apoc.convert.toTree(rs, true, { nodes: {Plaza: ['name'], Restaurant: ['name']} }) yield value RETURN value
05-22-2019 07:01 AM
Hello @melgamal, I've fallen into the same need and applied your query that worked for me, thanks by the way for sharing. However in the response I still get the _type and _id params. Did you manage to remove it as well from the response. Thanks
05-22-2019 07:07 AM
so far no, That's something i'm looking for too. P.S. Thanks to @jsmccrumb for the solution, not to me
All the sessions of the conference are now available online