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

504
Vistas
is there a way to get around using 'await' here?

I am trying to get all the documents in a subcollection by following the firebase documentation, however the error 'await is an reserved identifier' appears.

This is my code currently and I do not see where 'async' could be used with await and the documentation does not indicate that it would be used.

getAuth().onAuthStateChanged((user) => {
  if (user) {
    const app = initializeApp(firebaseConfig);
    const db = getFirestore(app);

    //reference to the subcollection of subjects in the user's document
    const subjectRef = collection(db, "users", auth.currentUser.uid, "subjects");

    const querySnapshot = await getDocs(subjectRef);

    querySnapshot.forEach((doc) => {
      console.log(doc.id, "=>", doc.data());
    });
  }
});

I have tried getting all the documents with db.collection.('users').document(auth.currentUser.uid).collection('subjects').get() where db = getFirestore(app), however this does not work as the error 'db.collection is not a function' appears and any soloutions I have found to it are not relevant as db is refering firestore not the real time database.

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

0

You need to make the callback async:

getAuth().onAuthStateChanged(async (user) => {
  if (user) {
    const app = initializeApp(firebaseConfig);
    const db = getFirestore(app);

    //reference to the subcollection of subjects in the user's document
    const subjectRef = collection(db, "users", auth.currentUser.uid, "subjects");

    const querySnapshot = await getDocs(subjectRef);

    querySnapshot.forEach((doc) => {
      console.log(doc.id, "=>", 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