The size of the auto generated ID in MongodDB is 12 Bytes
and the size of a big integer is 8 bytes
. I have a mongodb cluster on 4 machines running Ubuntu Server, but I am just testing things now. Inserts can be done only through one server which is a nodejs server, but updates and deletes can be done using various machines running a native c application all around the world and the nodejs server.
Since I have full control over inserts, wouldn't it be better to use an auto increment id?
How am i doing it :
i have this document
{id:0 latestId:174845423}
i very rarely increment it by 1, most of my inserts are bulk inserts, so the nodejs server modifies the documents to be inserted in a loop giving each one an incremented id, at the end of the insert operation i add i update the lastest id with the last id value.
"Auto-increment" is always a problem when working with a distributed system, as it creates a bottle-neck: Each new increment needs to read the previous data .. like some other parallel requests.
Generally speaking, "auto-increment" restricts parallelism, specially on distributed systems.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With