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

128
Views
get data from firestore returning metadata

Firebase version 9.6.9

I'm using onSnapshot function to get the data from the firestore.

collections

Code:

  const [posts, setPosts] = useState([])

  useEffect(() => {
    return onSnapshot(
      query(collection(db, 'posts'), orderBy('timestamp', 'desc')),
      (snapshot) => {
        console.log(snapshot.docs)
      }
    )
  }, [db])

snapshot.docs logs a metadata and not the data I need (the posts collection).

Log

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

0

The snapshot.docs is an array of QueryDocumentSnapshot. You can get data from your documents, by using .data() method on every snapshot as shown below:

return onSnapshot(
  query(collection(db, 'posts'), orderBy('timestamp', 'desc')),
  (snapshot) => {
    const result = snapshot.docs.map((d) => ({
      id: d.id,
      ...d.data()
    }))
    console.log('>>> Documents', result)
  }
)

The metadata has some information about the snapshots such as the source.

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!