Hi guys, why can’t my function return a result?
the result is always “undefined” but the console.log expects the right answer???
getAll() {
let values;
const db = firebase.firestore();
db.collection('userProfile').get().then((snapshot) => {
snapshot.docs.forEach(docs => {
db.collection('userProfile').doc(docs.id).get().then((snapshotData) => {
db.collection('userProfile').doc(docs.id).collection(`orderData`).get().then((oData) => {
values = oData.docs.map(flattenDoc);
return values;
console.log(values);
function flattenDoc(doc) {
return {id: doc.id, user: docs.id, name: snapshotData.data().firstName, ...doc.data()};
}
});
});
});
});