https://stackoverflow.com/questions/4356993/how-do-you-implement-an-auto-incrementing-primary-id-in-mongodb
MongoDB provides 2 way to auto increment _id (or custom key) .
Counter Collection
Here we need to create collection which stores the maximum number of keys and increment by 1 every time when we call this function.
Optimistic Loop
In this pattern, an Optimistic Loop calculates the incremented _id value and attempts to insert a document with the calculated _id value. If the insert is successful, the loop ends. Otherwise, the loop will iterate through possible _id values until the insert is successful.