1
votes

We are evaluating Neo4J for future projects.  Currently just experimenting with learning Cypher and its capabilities.  But one thing that I think should be very straightforward has so far eluded me.  I want to be able to see all properties and their values for any given Node.  In SQL that would be something like:

select * from TableX where ID = 12345;

I have looked through the latest Neo4J docs and numerous Google searches but so far I am coming up empty.  I did find the keys() function that will return the property names in a string list, but that is marginally useful at best.  What I want is a query that will return prop names and the corresponding values like:

name     :  "Lebron"
city     :  "Cleveland"
college  :  "St. Vincent–St. Mary High School"
1

1 Answers

1
votes

You may want to reread the Neo4j docs.

Returning the node itself will include the properties map for the node, which is typically the way you will get all properties (keys and values) for the node.

MATCH (n)
WHERE id(n) = 12345
RETURN n

If you explicitly just want the properties but without the metadata related to the node itself, returning properties(n) (assuming n is a node variable) will return the node's properties.

MATCH (n)
WHERE id(n) = 12345
RETURN properties(n) as props

With regard to how columns (variables) work, these are always explicit, so you don't have a way to dynamically get the columns corresponding to the properties of a node. You will instead need to use the approaches above, where the variable corresponds to either a node (where you can get at the properties map through the structure) or a properties map.

The main difference between this approach and select * in SQL is that Neo4j has no table schema, so you can use whatever properties you want on nodes of the same type, and those can differ between nodes of the same type, so there is no common structure to reference which will provide the properties for a node of a given label (you would need to scan all nodes of that label and accumulate the distinct properties to do so).