Message from JavaScript discussions

September 2020

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

Message permanent page


Now, wt I wanna do is...

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

— How should I do this?

— Async for loop


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

— Let allUsers = [];

async function getUsers(){......};

— 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

— You should try to minimize the amount of requests. So in this case I would gather all the user IDs and then do something like getUsersByIds. No clue how mongoose works though

Message permanent page