Message from JavaScript discussions

September 2020

— If two users share a role, you have to fetch it twice.


So before you retrieve the data, you should map the role IDs, then filter unique, and then get all with`Promise.all()`

— But I am certain, any proper db tooling should have an in operator.. Like SQL: select * from roles where id in [0,1,2,3,4]

Message permanent page

— That's different use case.

— Why? you want to get all roles for a set of users

— What is the expected end result?

— I want to get userId and populate the other object with that.

— For each user.

— ..

— Router.get("/users", async (req, res) => {
let users = [];
try {
async function listAllUsers(nextPageToken) {
var listUsersResult = await admin.auth().listUsers(1000, nextPageToken);
if (!listUsersResult)
return res.status(404).json({ msg: "No user found!" });

listUsersResult.users.forEach(async (userRecord) => {
let uid = userRecord.toJSON().uid;
let mUser = await User.findOne({ uid }).populate("role", ["title"]).lean();
mUser.photoUrl = userRecord.photoURL; =; = userRecord.displayName;
setTimeout(() => res.status(200).json({ users }), 2000);
// if (listUsersResult.pageToken) listAllUsers(listUsersResult.pageToken);


Message permanent page

— If console.log out of forEach even then users array is empty.

— 1. use map then you don't need to work with intermediate variables and fill them. you can then assign directly.

2. I have no idea of mongodb, but this looks inefficient. not sure what .lean() does. maybe there is some optimization magic

Message permanent page