My data is a bunch of individuals with a “department”. Every department has n sub departments. The sub departments have random names. But the subdepartments/subsections inside each department are always the same.
I have a collection full of stuff like this:
userId: 1 displayName: joe department: sales americanClient: disney europpeanClient: siemens australianClient: kanguru userId: 3 displayName: mary department: sales americanClient: ford europpeanClient: bmw australianClient: koala
(in this case american, european and australian client are the subsections)
userId: 2 displayName: sammy department: banking mainfunction: "client handling" userId: 3 displayName: mary_banking department: banking mainfunction: "client handling"
in this case main function is the only subsection.
Then I have another collection that lists the subsections of each department:
department:banking sections:[mainfunction] department: sales sections: [americanClient, europpeanClient, australianClient ]
I have a million of these users, and i want to produce a list of the available distinct departments and sub departments. Mongo distinct is not available directly, and rawCollection distinct only works server side.
What I want to happen:
As my webpage, I want a list of departments, then I click on “sales” and it produces 3 menus, one showing all existent European clients, one showing all existent American clients and one showing all existent Australian clients.
As I click these specific clients, I will produce a list of the users connected to them.
How do i do this? Since the list of europeanclients exists only inside the user list, the obvious way for me is to use distinct.
Since that is not available, I was doing a find for all, then turning that into a set. But that takes too much time because I have too many users.
Is there a way I can alter my “schema” to go around this?
Each subsection/subdepartment is just a string, nothing else, so I don’t have a collection for them.
Help would be most welcome