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

414
Views
Unable to fetch docs ids in firebase firestore using NodeJS (Google cloud functions)

Need to fetch all the document ids present in the collection.

// get all users' id
    const allUserIds = [];

    db.collection("users").get().then((querySnapshot) => {
        console.log(querySnapshot._docs);
        querySnapshot.docs.forEach((doc) => {
            allUserIds.push(doc.id);
        });
    });
    console.log(allUserIds);

The list, allUserIds is getting empty in log.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

get() is asynchronous and returns a promise. You will need to learn how promises work in JavaScript if you want to use Firestore effectively. For now, put the console log inside the callback to see that the query works.

    db.collection("users").get().then((querySnapshot) => {
        console.log(querySnapshot._docs);
        querySnapshot.docs.forEach((doc) => {
            allUserIds.push(doc.id);
        });
        console.log(allUserIds);
    });

It will be up to you to understand JavaScript promises and use them correctly for your application - it is a general concept not unique to Firestore.

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!