I’ve to store employee(considering 50 millions records for future) data for each company(let’s say more than 1000 companies) what approach I should follow.
#1- Should I use single collection for user’s info?
#2- Should I use multiple collection on the basis of states of country(I’m thinking to create separate collection for each state of the country) to store user’s info.(so I will ask first state from user then Email & password during login). is it good approach.
Or any other optimised approach.
>Solution :
In my experience, the best way is to use a single collection with well-defined document structures and indexes for efficient storage and retrieval of employee data across multiple companies.
Using a single collection allows for easier management, scalability, and querying of data. You can include fields like company ID or state in each document to differentiate between companies or states.
Note:
By using indexes efficiently and structuring your documents appropriately, you can optimize performance without the need for separate collections. This approach simplifies data retrieval and ensures better performance as the dataset grows. Additionally, consider sharding for horizontal scaling if needed in the future.