Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
06-13-2022 08:45 AM
I am just trying to learn Neo4j with cyper
here is the use case I want to find all the nodes with and without relationships
06-13-2022 09:52 AM - edited 06-13-2022 10:08 AM
Try the following if you want a list of each node that includes its list of relationships. Nodes without relationships will have null values for the relationship properties:
match(n)
optional match (n)-[r]-()
with id(n) as node, collect({id: id(r), type: type(r), startNode: id(startNode(r)), endNode: id(endNode(r))}) as rel
return {node: node, relationships: rel}
Try the following if you just want a list of all nodes and all relationships not correlated with each other:
match(n)
with collect({id: id(n), labels: labels(n)}) as nodes
call {
match (x)-[r]-(y)
where id(x) < id(y)
return collect({id:r, type: type(r), startNode: id(startNode(r)), endNode: id(endNode(r))}) as relationships
}
return nodes, relationships
Change the node's 'label' property to be what you want, and/or add additional properties from the node.
All the sessions of the conference are now available online