Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

156
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda