80/20 Rule

hi there,

how can we create 80-20 rule in mongo database, my requirement is identify customers who generate 80% of sales

Please advise


Without knowing how your database is structured, I will only be able to give general help.

Generally the approach to this is to write a simple Mongo query that identifies customers and total sales (do you mean revenue?) by customer.

Then it is a matter of calculating what you mean by 80% of sales. In this case, I assume your question is trying to answer which customers generate 80% of TOTAL sales. First calculate what 80% of your total sales is. E.g. if your total sales are 100 units, 80% would be 80 units.

Order your customers by total sales, with the customers with the most sales at the top. Then loop through this list and save the customer while adding their sale amount to an accumulator variable. Stop once that variable is greater than or equal to 80% of your total sales. Now you have a list of customers that generate about 80% of your company’s sales.

In SQL, this would be accomplished by a query/cursor. I don’t write a lot of NoSQL/Mongo queries, I cannot advise there.