2

I am having trouble coming up with a good performing mongodb model. I have 2 million employees. I need to store an array of supervisor ids, that can access an employee. Picture data like this..

{
'fullName':'Jonathan Smith',
'employeeId':'8675309',
'supervisors':[1234,7654,45676,34543,56545]
}

Each array could have hundreds of elements. The elements can also fluctuate. So I will need to perform quick $puts and $pulls to add and subtract elements from the array.

I good example operation would be..we have a supervisor 5555 that now has access to 510,000 employees. So I need to update those 510,000 employees, adding 5555 to those employees arrays.

A query would then be, give me all of the employees supervisor 5555 has access to.

is there a better way to do this? Are there things I can do to insure performance.

1 Answer 1

1

It sounds like those 510,000 employees might actually belong to a different class or entity than simply "employees managed by supervisor 5555". Call this class "A". The employees would be marked as belonging to class "A" (and possibly other classes), and 5555 would be marked as the manager of "A", but not of the individual employees. That is under the assumption that it is more likely for the manager of class "A" to change, than all 510,000 employees falling out of class "A".

Sign up to request clarification or add additional context in comments.

3 Comments

Ok I see what you are saying. This would keep the list pf array elements smaller, due to the face that supervisors could possibly have the same group A. So lets say I took this approach. What about the fact that I still have 2 million employees and need to perform push and pull operations across these employees adding group Ids. Any issue with performance?
2 million documents is not very much. Unless you frequently need to update all of these documents in real-time, with interactive response, that's not a big deal. You should be able to update a few thousand documents per second.
I recently wrote a blog post about growing arrays in MongoDB: robinwieruch.de/?p=159 There you can see a benchmark for of this behaviour.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.