I want to get the data from mongoose. Here is my code:
let data = [];
const getUserInfo = () => {
UserInfo.find({}, function(err, docs){
data = docs;
console.log(data); //first log
});
console.log(data); //second log
};
getUserInfo();
The first log will print the right data, but the second log will return an empty set. Why does that happen?