Message from JavaScript discussions

September 2020

— Ok

— 

I'm using firebase admin sdk to list all the users. And the user is stored in mongodb with the corresponding uid.

— Now, wt I wanna do is...

forEach user, I want to retrieve the corresponding user role which is stored in the mongodb collection.

Message permanent page

— How should I do this?

— Async for loop

— 

for(let user of users) await db.getUserRole(user);

— Let allUsers = [];

getUsers();
async function getUsers(){......};
console.log(allUsers);

— Here, console log is called before getUsers.

— So it return an empty array

— Urg

— There should be native mongoose tooling to achieve that

— Depends on how you built your Database Controllers. He said forEach which assumes a loop. MongoDB is capable of that.

Message permanent page