In my current project, we are utilizing MongoDB as our primary database system alongside JavaScript/NodeJS for the server-side operations. We now face the challenge of integrating with an external partner.
Our partner's API necessitates a unique integer value for the operation number. To meet this requirement, we initially decided to generate this number by combining a 4-byte timestamp and a 3-byte random increment value sourced from the ObjectId
. However, the numbers produced are excessively high, resulting in a loss of precision.
The following is the existing 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);
};
Are there any recommendations for improving this process or altering it to reach the desired outcome?