Wednesday, 3 May 2017

Using .find of Mongoose to get a list of all users and create an array

Hello guys first thanks for your help, I'm kind of newbie in programing and I'm having some problems, I'm trying to get a list of the users in my server but i doesn't work, the list is always empty.

That's my code:

function gettingRegion(){
   var listUsers = []
    User.find({},function(err, response){
            if(!err)
            {
                listUsers = response
            }
    })
    console.log(listUsers)
}

I tried Async, putting a return inside de .find and creating a function outside the .find but i didn't work, why is not working?

Thanks



via Luiz Fernando Lobo

No comments:

Post a Comment