I was coding a simple Google Firebase Cloud Firestore system in node.js, and I put the script in another file. I wrote a function to get the data from a document, but when I tested it, it didn't work. Doing a console.log from the .then() works perfectly fine, but I need to pass the value to another script.
Function:
// firebase.js
async function getAllDocsFromCollection(collection){
let data = [];
db.collection(collection).get().then((querySnapshot) => {
querySnapshot.forEach((doc) => {
data.push(doc.id);
data.push(doc.data());
});
console.log(data); // Logs correct data
});
console.log(data); // Doesn't log correct data
return data; // Doesn't return correct data
}