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

145
Views
MongooseError: Query was already executed: Users.find({ username: 'b' })

Code block:

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)=>{
                  
                await userModel.find({username:whoimFollowing},async (err,whoimFollowingdata)=> {
                       console.log(whoimFollowingdata) 
                       followingarray.push(whoimFollowingdata)
                    
                    })
        
                })
           
             }).then((res)=> {
           
             })
                }catch(e){
                   
                }
            }

When I added await to the UserModel.find Thats when this error was caused, How Can I Stop This Error From Happening?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

the function itself is a callback so adding the async to the getFollowers() is what is causing the error. Remove the async with the try and catch from the getFollowers() and the code will work.

export const getFollowers = () => {
    console.log(req.body)
    ...
    ...
    userModel.find({...,async (err,data) => {...}})
}
about 4 years ago · Juan Pablo Isaza Report
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!