I'm involved in a project where we use MongoDB as the primary database system and JavaScript/NodeJS for the server side. We need to make an integration with external partner.
Our partner's API requires operation number which should be a unique integer value. We decided to use a combination of 4 byte timestamp and 3 byte random increment value from ObjectId, but the result numbers are too high and we lose precision.
Here is the procedure
var getUniqueIntFromObjectId = function (object_id) {
var res = null;
object_id = object_id.toString();
res = parseInt(object_id.substring(0, 8), 16).toString() + parseInt(object_id.substring(18, 24), 16).toString();
return parseInt(res, 10);
};
How can we improve this procedure, or change it to achieve the goal?