I found how the Parse Server generates a new Id on creation here.
The comment documentation above states that the below function is getting called to generate a new id for Parse Server.
I still don't know why it has to create an id in its way rather than using Mongo's native one. It shall help to remove Parse Server dependency easily.
Please find the code below in c# that I am using to generate a new id like the parse server. I have not tested it with all aspects but, I think it will pass most if not all test cases of others.
/// <summary>
/// Randoms the string.
/// </summary>
/// <param name="length">The length.</param>
/// <returns></returns>
public static string RandomString(int length)
{
string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "0123456789";
StringBuilder res = new();
using (RNGCryptoServiceProvider rng = new())
{
byte[] uintBuffer = new byte[sizeof(uint)];
while (length-- > 0)
{
rng.GetBytes(uintBuffer);
uint num = BitConverter.ToUInt32(uintBuffer, 0);
res.Append(chars[(int)(num % (uint)chars.Length)]);
}
}
return res.ToString();
}
/// <summary>
/// Gets the new object identifier.
/// </summary>
/// <param name="size">The size.</param>
/// <returns></returns>
public static string GetNewObjectId(int size = 10)
{
return RandomString(size);
}
I hope this sample code helps recreate the logic in your preferred language.