Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

170
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!