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

152
Views
How to retrieve documents in firestore order with timestamp with React

I wrote the following code.

const salons = query(collection(db, "user"), orderBy('', "desc"), limit(5))
const querySnapshot = await getDocs(salons)
await querySnapshot.forEach((doc) => {
    console.log(new Date(doc._document.version.timestamp.seconds * 1000).toString())
    //processing
})

I want to sort the orderby by "doc._document.version.timestamp.seconds" which is displayed in console.log.

But I don't know how to do it. This date is automatically registered by firestore, so the position of the value is different. Does anyone know how I can sort it?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Firestore can only order/filter data on values that it has indexes for. Indexes are only created for fields in your document (and the document ID), not for implicit metadata such as the timestamp it keeps internally.

There is no way to order Firestore results based on the internal timestamp. If you want to be able to order documents on a timestamp, you'll have to store that timestamp as a field in the document, and then pass that field name to orderBy.

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!