Message from JavaScript discussions

September 2020

— 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.

— 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

— You can do that with ~5 users. but not with 100

— Also, you just want to fetch the roles only once

— 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()`

Message permanent page

— 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.