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

864
Views
Obtener todos los documentos de una colección en Firestore

Hola, estoy comenzando con javascript y react-native y estoy tratando de resolver este problema durante horas. ¿Alguien puede explicarme cómo obtener todos los documentos de la colección firestore?

He estado intentando esto:

 async getMarkers() { const events = await firebase.firestore().collection('events').get() .then(querySnapshot => { querySnapshot.docs.map(doc => { console.log('LOG 1', doc.data()); return doc.data(); }); }); console.log('LOG 2', events); return events; }

El registro 1 imprime todos los objetos (uno por uno) pero el registro 2 no está definido, ¿por qué?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

El ejemplo en la otra respuesta es innecesariamente complejo. Esto sería más sencillo, si todo lo que desea hacer es devolver los objetos de datos sin procesar para cada documento en una consulta o colección:

 async getMarker() { const snapshot = await firebase.firestore().collection('events').get() return snapshot.docs.map(doc => doc.data()); }
over 4 years ago · Santiago Trujillo Report

0

si quieres incluir id

 async getMarkers() { const events = await firebase.firestore().collection('events') events.get().then((querySnapshot) => { const tempDoc = querySnapshot.docs.map((doc) => { return { id: doc.id, ...doc.data() } }) console.log(tempDoc) }) }

De la misma manera con la matriz

 async getMarkers() { const events = await firebase.firestore().collection('events') events.get().then((querySnapshot) => { const tempDoc = [] querySnapshot.forEach((doc) => { tempDoc.push({ id: doc.id, ...doc.data() }) }) console.log(tempDoc) }) }
over 4 years ago · Santiago Trujillo Report

0

Lo hice funcionar de esta manera:

 async getMarkers() { const markers = []; await firebase.firestore().collection('events').get() .then(querySnapshot => { querySnapshot.docs.forEach(doc => { markers.push(doc.data()); }); }); return markers; }
over 4 years ago · Santiago Trujillo 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!