Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

230
Vistas
Retrieving all neo4j <Record> keys data without using .get()

I am using neo4j-driver in order to run my query:

import neo4j from "neo4j-driver";

const driver = neo4j.driver(
  process.env.NEO4J_URI,
  neo4j.auth.basic(process.env.NEO4J_USER, process.env.NEO4J_PASS)
);

export const session = driver.session();

When I retrieve the results, I now have to map trough all of the records and retrieve all the values in order to format the data that is otherwise in the _fields property. Is there a way to do this inside the DB query, or without using separate .get calls. I am worried about performance, since the number of nodes will be be big, and mapping trough them could burn unnecessary resources.

export const getColorsList = async (): Promise<Color[]> => {
  const readQuery = `
    MATCH (c:Color)-[a:ASSOCIATED_WITH]->(t:Tag)
    WITH COLLECT(t.name) AS tags, c
    RETURN  c.alternativeNames AS alternativeNames, c.hex AS hex, c.name AS name, c.temperature AS temperature, tags AS tags
  `;
  const readResult = await session.readTransaction((tx) => tx.run(readQuery));

  const colors: Color[] = readResult.records.map((color) => {
    const alternativeNames = color.get("alternativeNames");
    const hex = color.get("hex");
    const name = color.get("name");
    const temperature = color.get("temperature");
    const tags = color.get("tags");
    return {
      alternativeNames,
      hex,
      name,
      temperature,
      tags,
    };
  });

  return colors;
};
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can try using a map projection in your query, something like this:

MATCH (c:Color)-[a:ASSOCIATED_WITH]->(t:Tag) WITH COLLECT(t.name) AS tags, c RETURN c{.alternativeNames, .hex, .name, .temperature, tags: tags}

Here's the link to the documentation.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda