I am using Firestore to handle my data for my website. What the code below should do. I have users on my website. The data of all users are saved under /users. There the data can be found at (users/{user_uid}/...). I also has another ref called "classes". There are user_uids are saved. That's important because it works like a group of users. FOr example: (/classes/Q11). In the document Q11, a list can be found with all user_uids, which are in this Q11 group.
The code below gets the list of two groups and search after their name. After that, the code does a little stuff that is not relevant and then it's finished.
In the first step, he gets the group list completely without troubles. I printed it out and everything is correct. But when I print the list of names of the second process, there are not all names. What am I doing wrong? Users get lost?
["Q11", "Q12"].forEach(function(class_year) {
db.collection("classes").doc(class_year).get().then(function(doc) {
if (doc.exists) {
const data = doc.data();
const members = data.members;
members.reduce((chain, el) => {
console.log("SEARCHING: " + el);
return chain
.then(() => db.collection("users").doc(el).collection("user_data").doc("u").get())
.then(doc => {
const data = doc.data();
var member_name = data.name;
/*
console.log("[DEBUG] Adding user: " + member_name);
console.log("____________________________________________________");*/
console.log("CALLING: " + member_name);
const html = fillTemplate(el + "es111", el + "es112", el + "es121", el + "es122", member_name);
document.getElementById("main_padding_" + class_year).insertAdjacentHTML('beforeend', html);
})
.then(() => {
//some little stuff
})
}, Promise.resolve()).then(console.log("finished"));
} else {
console.log("No such document!");
}
}).catch(function(error) {
console.log("Error getting document:", error);
});
});
Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire