Using Cypher how can I get all nodes in a graph? I am running some testing against the graph and I have some nodes without relationships so am having trouble crafting a query.
The reason I want to get them all is that I want to delete all the nodes in the graph at the start of every test.
When you want to return all nodes, relationships and paths found in a query, you can use the * symbol. This returns the two nodes, the relationship and the path used in the query.
The graphs in the Neo4j Graph Data Science Library support properties for relationships. We provide multiple operations to work with the stored relationship-properties in projected graphs. Relationship properties are either added during the graph projection or when using the mutate mode of our graph algorithms.
An OPTIONAL MATCH matches patterns against your graph database, just like a MATCH does. The difference is that if no matches are found, OPTIONAL MATCH will use a null for missing parts of the pattern. OPTIONAL MATCH could be considered the Cypher equivalent of the outer join in SQL.
Cypher is Neo4j's graph query language that lets you retrieve data from the graph. It is like SQL for graphs, and was inspired by SQL so it lets you focus on what data you want out of the graph (not how to go get it).
So, this gives you all nodes:
MATCH (n) RETURN n;
If you want to delete everything from a graph, you can do something like this:
MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE n, r;
Updated for 2.0+
Edit: Now in 2.3 they have DETACH DELETE
, so you can do something like:
MATCH (n) DETACH DELETE n;
Would this work for you?
START a=node:index_name('*:*')
Assuming you have an index with these orphaned nodes in them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With