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

268
Vistas
Uncaught (in promise) TypeError: querySnapshot.forEach is not a function React Native

I have a 'users' collection on Firebase. This collection has some fields in it which I'd like to render on the screen

I have a class Home which contains the following function:

const db = firebase.firestore();

    
export class Home extends Component {
  constructor(props) {
    super()
  }
  componentDidMount(){
     db.collection('/users')
     .doc(firebase.auth().currentUser.uid)
     .get()
     .then(querySnapshot => {
        querySnapshot.forEach(uid => {
        let data = uid.data();
           console.log(data);
        })
      })
  }
}

Without the .doc(firebase.auth().currentUser.uid), I get the all the fields of all the users on the screen but when I add this, to get the details per user, I encounter the error "Uncaught (in promise) TypeError: querySnapshot.forEach is not a function". Thanks in advance for the help.

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You are using get() on a DocumentReference which returns a DocumentSnapshot that contains data of a single document only and there isn't any forEach method present on it. So just using data() directly on the snapshot should do. Try refactoring the code as shown below:

componentDidMount() {
  db.collection('/users')
    .doc(firebase.auth().currentUser.uid)
    .get()
    .then((docSnapshot) => {
      console.log(docSnapshot.data())
    })
}

If you are trying to get all the documents from users collection, then use get() on CollectionReference (essentially remove the .doc(uid)) as shown below:

componentDidMount() {
  db.collection('/users')
    .get()
    .then((querySnapshot) => {
      querySnapshot.forEach((doc) => {
        console.log(doc.data())
      })
    })
}
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