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

202
Vistas
Returning Firestore Query If Nothing Is Found In JavaScript

I am trying to console.log "Not Found" if a search query in Firestore isn't found. At the moment I am using the following to perform the query which looks through all documents for an email = "123@test.com".

This works fine if the document contains what I am searching for but I cant get it to console.log anything if nothing is found

db.collection("test").where('email', '==', "123@test.com").get()

        .then(function (querySnapshot) {

            querySnapshot.forEach(function (doc) {
                console.log(doc.data())
            });

        }).catch(function (error) {
            console.log("Error getting document:", error);
        });
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If no matching document is found then the empty property of the QuerySnapshot will be true:

db.collection("test").where('email', '==', "123@test.com").get().then(qSnap => {
  if (qSnap.empty) {
    console.log("Not found")
  } else {
    // proceed
  }
})
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