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){
}
}
im getting the error:
this issue happened when i added await to the UserModel.find function because im trying to add data i find from it into an array without the await would cause me problems
const err = new MongooseError('Query was already executed: ' + str);
^
MongooseError: Query was already executed: Users.find({ username: 'b' })
at model.Query._wrappedThunk [as _find] (C:Portfolio ProjectsActual socialmediaAppServernode_modulesmongooselibhelpersquerywrapThunk.js:21:19)
at C:Portfolio ProjectsActual socialmediaAppServernode_moduleskareemindex.js:372:33
at processTicksAndRejections (node:internal/process/task_queues:78:11) {
originalStack: 'Errorn' +
' at model.Query._wrappedThunk [as _find] (C:\Portfolio Projects\Actual socialmediaApp\Server\node_modules\mongoose\lib\helpers\query\wrapThunk.js:25:28)n' +
' at C:\Portfolio Projects\Actual socialmediaApp\Server\node_modules\kareem\index.js:372:33n' +
' at processTicksAndRejections (node:internal/process/task_queues:78:11)'
}