Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

195
Views
.push() not pushing into array with mongodb

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){
                   
                }
            }
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!