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

386
Vistas
Firestore: Unable to read document data (Uncaught TypeError: docSnap.exists is not a function at HTMLFormElement)

I am a new developer with no experience in Web apps. I have a collection called "users" in Firestore in which the document IDs are the user's emails. I am trying to read the data in one of the documents following the example provided by Firebase here

I get two errors:

  • First one is the use of "await": Uncaught SyntaxError: Unexpected reserved word.
  • Second is this message: Uncaught TypeError: docSnap.exists is not a function at HTMLFormElement.

I bypassed the first one by ommiting "await", but cannot avoid the second. Have you got any idea of what is wrong with my code?

console.log(docSnap) gives the following message: "Promise {pending}"

Thanks.

requestForm.addEventListener('submit', (event) => {
event.preventDefault();

const user = auth.currentUser;
const docSnap = await getDoc(doc(db, "users", user.email));

    if (docSnap.exists()) {
        console.log("Document data:", docSnap.data());
        } else {
        console.log("No such document!");
    }
})

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

0

Looks like you return a Promise and it does not meet the requirements of async/await. Try this way.

getDoc(doc(db, "users", user.email)).then(docSnap => {
  if (docSnap.exists()) {
    console.log("Document data:", docSnap.data());
  } else {
    console.log("No such document!");
  }
})
about 4 years ago · Juan Pablo Isaza Denunciar

0

Be careful, getDoc vs getDocs

For single document

import { doc, getDoc } from "firebase/firestore";

const docRef = doc(db, "cities", "SF");
const docSnap = await getDoc(docRef);

if (docSnap.exists()) {
  console.log("Document data:", docSnap.data());
} else {
  // doc.data() will be undefined in this case
  console.log("No such document!");
}

For all document

import { collection, getDocs } from "firebase/firestore";

const querySnapshot = await getDocs(collection(db, "cities"));
querySnapshot.forEach((doc) => {
  // doc.data() is never undefined for query doc snapshots
  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