Search code examples
neo4jcypher

Obtain node property values in an array


Can I return a node property values in an array? Say I create the following node in neo4j:

CREATE (p:Person {name:'Ernesto', gender:'male', town:'Cham'})

I can produce the keys by using:

MATCH (p:Person {name: 'Ernesto'} )
RETURN keys(p)

will produce:

[name, gender, town]

what is the right method for obtaining:

['Ernesto', 'male', 'Cham']

as a collection, better yet, obtaining a map:

{name: 'Ernesto', gender: 'male', town: 'Cham'}

Not interested in obtaining this info visually as a node properties as it always contains the node id. I'm interested in a generic approach so it can be used variably.

Thanks for any help.


Solution

  • Unfortunately, it's not possible to return all properties of a node with Cypher. Would be a great feature though.

    You get something close to it with:

    MATCH (n) RETURN str(n) LIMIT 1
    

    This returns a string representation that you can parse in your application:

    Node[817903]{key:"value", key2:"value2"}