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

257
Visualizações
Javascript Firebase Firestore returning disordered data

When I run the following using the JS client sdk

import { firestore } from "../../../firebase";

export default async (userId) => {
  const userRef = firestore.collection("users").doc(userId);
  const userDoc = await userRef.get();

 
  if (!userDoc.exists) {
     throw new Error("User doesn't exist");
  }

  console.log(JSON.stringify(userDoc.data(), null, 2));

  const userData = {
    id: userDoc.id,
    ...userDoc.data(),
  };

  return userData;
};

multiple times, for the same userId, without having changed anything in the DB, I get the same data but with disordered fields:

{ // 1st fetch
   name: "a",
   age: 10,
   avatar: {
      uri: "x",
      thumbnailUri: "y"
   }
}


....


{ // 2nd fetch
   name: "a",
   avatar: {
      thumbnailUri: "y",
      uri: "x"
   },
   age: 10
}

What is the reason behind this? Is it possible to always get an ordered version?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Firestore documents contain data in a JSON format, and there is no way of guaranteeing the order of fields in a JSON object. If you need your fields ordered, you'll have to do it on the client.

Please see this post for more information

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