cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Return all nodes properties

Hi,

I'm an early begginer in Neo4j and i need some help with the return syntax.

I want to return all nodes properties but i'm not able to get them without null values and repeated nodes.

This is how i create it.

CREATE (a: Formulario {Nombre:'PS2115'})
CREATE (b: Datos_Internos {Autor:'Sergio', Fecha:'07/02/2022', Identificador:'847', Revision:'3', Descripcion:'Una descripcion bonita'})
CREATE (c: Datos_Cliente {Nombre:'Igeteam', Direccion:'Parque Tecnologico'})
CREATE (d: Persona_Contacto {Nombre:'Gerente', Telefono:'654789321', Email:'Gerente@gamil.com', Cargo:'Gerente'})

CREATE (a)-[:Datos]->(b)
CREATE (a)-[:Datos]->(c)
CREATE (c)-[:Contacto]->(d)

And this is the resulting graph.

3X_e_3_e32a69496553f7a29a4a6087a85a4015b22d29a8.png

Now i am trying to return the properties and values of the nodes.

MATCH (f:Formulario{Nombre:'PS2115'})-[:Datos]->(c)
OPTIONAL MATCH(c)-[:Contacto]->(d)
WITH f,c,d
RETURN{Proyecto: properties(f), Datos: properties(c), Persona_Contacto: properties(d)}

3X_0_8_08e081b2111fbc26131f4eec4286a64c1126fc59.png

I want to know if it is possible to get only one message with all the information of the nodes properties.

Thanks!!

1 ACCEPTED SOLUTION

If you want them collected and don't care which Persona_Contracto is associated with which Datos.

MATCH (f:Formulario{Nombre:'PS2115'})-[:Datos]->(c)
OPTIONAL MATCH(c)-[:Contacto]->(d)
WITH f, collect(properties(c)) as datos, collect(properties(d)) as persona_contacto
RETURN{Proyecto: properties(f), Datos: datos, Persona_Contacto: persona_contacto}

If you want to the persona_contacto associated with its dates (query assumes zero or one d nodes per c node, and I didn't know what to call label XX):

MATCH (f:Formulario{Nombre:'PS2115'})-[:Datos]->(c)
CALL {
WITH c
OPTIONAL MATCH(c)-[:Contacto]->(d)
RETURN {datos: properties(c), persona_contacto: properties(d)} as datos
}
RETURN{Proyecto: properties(f), XX: collect(datos)}

View solution in original post

2 REPLIES 2

@sfuertes

If possible, you could use the Apoc procedures, in particular this one apoc.map.merge - APOC Documentation (or maybe also the apoc.map.mergeList - APOC Documentation if you have a lot of maps)

MATCH (f:Formulario{Nombre:'PS2115'})-[:Datos]->(c)
OPTIONAL MATCH(c)-[:Contacto]->(d)
WITH f,c,d
RETURN apoc.map.merge( apoc.map.merge(properties(f), properties(c)), properties(d))

If you want them collected and don't care which Persona_Contracto is associated with which Datos.

MATCH (f:Formulario{Nombre:'PS2115'})-[:Datos]->(c)
OPTIONAL MATCH(c)-[:Contacto]->(d)
WITH f, collect(properties(c)) as datos, collect(properties(d)) as persona_contacto
RETURN{Proyecto: properties(f), Datos: datos, Persona_Contacto: persona_contacto}

If you want to the persona_contacto associated with its dates (query assumes zero or one d nodes per c node, and I didn't know what to call label XX):

MATCH (f:Formulario{Nombre:'PS2115'})-[:Datos]->(c)
CALL {
WITH c
OPTIONAL MATCH(c)-[:Contacto]->(d)
RETURN {datos: properties(c), persona_contacto: properties(d)} as datos
}
RETURN{Proyecto: properties(f), XX: collect(datos)}