im trying to map through users in a database and .push() each of them into an array so i cant send it as a response to the client but its returning an empty object im not sure if the data has been pushed and its returning before the array is updated?
export const getFollowers = async (req,res) => {
console.log(req.body)
const profilename=req.body.profilename
const followingarray = []
try{
await userModel.find({username:profilename},async (err,data)=> {
const following = data[0].following
following.map(async(whoimFollowing)=>{
const users_found = await userModel.findOne({ username: whoimFollowing }).then(
(data)=> {
console.log(data)
followingarray.push(data)})
})
await res.status(208).json(followingarray)
})
}catch(e){
}
}