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

177
Vistas
ReactJS , Get data from Firebase order issue

Get data from the firebase it's fine but when I send data I want that the last data is after the last item of the array but I don't know what is the default order but the order is not as I want like:

[a,b,bc] its data get from firebase when I send c and d its look like

[c,a,b,bc] or [c,a,d,b,bc] like what is the default order i did't understand

i want like:

[a,b,bc,c] or [a,b,bc,c,d]

Get data from firebase

 db.collection("messages").onSnapshot((snap) => {
      let messages = [];
      snap.docs.forEach((doc) => {
        messages.push({ ...doc.data(), id: doc.id });
      });
      console.log(messages);
      setmessge(messages);
    });

Send data into firebase

 const dataInput = {
      date_time: new Date().toLocaleString(),
      message,
      sender_id: userId,
    };
    db.collection("messages").add(dataInput);
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The Firebase documentation states clearly how the matching query documents are returned based on their ID ascending order:

By default, a query retrieves all documents that satisfy the query in ascending order by document ID.

You can specify an orderBy criteria on your collection references when retrieving data to get it sorted per the criteria:

db.collection("messages")
  .orderBy("date_time")
  .onSnapshot((snap) => {
    // ...   
});
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