sac Dahal
sac Dahal

Reputation: 1241

generating random key as unique id(running out of random numbers.)

So I have a scenario where I need unique random 5 or 6 digit numbers to be stored as booking Id of my customers. So I simply create random numbers using.

var booking_id_customer = Math.floor(Math.random()*900000) + 10000;

Than store them in my mongodb as

    booking_id_customer: {
    type: Number,
    index: { unique: true }
},

But I am running out of numbers now, I don't have idea about how to handle this but the requirements are 5 or 6 digit random numbers only. How to handle this situation any hint will be a great idea.

Upvotes: 0

Views: 87

Answers (1)

Sergey Yarotskiy
Sergey Yarotskiy

Reputation: 4804

Well, there is no solution. Architectural flaws are the most difficult to solve. Somebody were need to think about limit when designed the system.

Simplest thing you can do now, is to add more numbers. Also, if you have limit by length only, you can use mix of numbers and letters.

Upvotes: 2

Related Questions