I tried to fetch data from firebase firestore, which I get what I wanted by console.log(). But when I tried to store what I get to array using push(). It gives me empty value in return. Here is my code:
app.post('/getMemberInfo', async (req, res) => {
var memberKeyList = req.body.member
var memRef = await db.collection("user")
let newArray = []
memberKeyList.forEach((row) => {
memRef.doc(row.MemberID).get().then((doc)=>{
newArray.push(doc.data())
console.log(doc.data())
})
})
res.send(newArray)
})
Here on console.log I got all data, but in newArray it returns empty array. What did I do wrong here? Any solution?