2

i have question please, there is an old code where they manually made a function to randomly generate an id, the id type is a number and not a string. since it not that safe they lately found a duplicate id. What's the best and safest solution to fix this, i thought of using UUID to generate an id but uuid only generate strings while it's a number? if i change the id type to string would it cause a problem with old records?

Ps: they used Express.js and mongoose

1 Answers1

0

How can I create unique IDs with JavaScript? You can try methods in this to replace the function. Choose one which fits you profile and needs the best.

GUNNS
  • 21
  • 2
  • I can use UUID or objectId but the problem is that it has to always be a number – Ramzi Mahnoune Oct 09 '22 at 17:07
  • Try something like this ? ``` const uid = function(){ return Date.now().toString(36) + Math.random().toString(36).substr(2); ``` Convert the string in the above one to a number ? – GUNNS Oct 09 '22 at 17:16