I am struggling to get this working properly. I have this function in my nodejs backend
let data = [];
let lists = [];
var userId = request.params.userId;
var coll = db.collection("forms");
var query = coll.where("formUser", "==", userId);
await query.get().then(function (querySnapshot) {
querySnapshot.forEach(function (doc) {
var forms = doc.data();
var listIDs = doc.data().formLists;
listIDs.forEach(listId => {
db.collection("lists").where("listId", "==", listId).get().then(function (snapshot) {
snapshot.forEach(function (d) {
lists.push({ "id": d.data().listId, "text": d.data().listName });
});
});
});
forms.formLists = lists;
data.push(forms);
});
});
The second loop for some reason isn't just working, the result of data is from the first loop and if I put the same function inside my javascript frontend, I get the complete data with the listIDs result.
Any ideas please?