Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

229
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda