usersList is a valid array with string values, User.findById(userId) returns an user as expected. I think the problem lies in the block of scope because forEach method and FindById method works perfect.
I've tried many methods of array returning each value. (e.g. map and filter) I've read many documents about advanced MongoDB technique, the block of scope and array methods.
const usersList = camp.usersList;
let users = [];
usersList.forEach((userId) => {
User.findById(userId, (err, user) => {
if(err) return res.redirect('/admin/db');
users.push(user);
})
})
console.log(users);
The output should be [user1, user2, ...], not [].