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