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

200
Views
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 answers
Answer question

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 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!