In MongoDB, a problem arises with the counter in the object ID that may limit its uniqueness. The object ID is only unique as long as the counter does not overflow! The counter overflow problem is when the counter has reached its maximum capacity, leading to documents having the same object ID. Therefore, the object ID is almost unique but not 100% unique!
Here is why: The counter is being allocated three bytes. This means it has the capacity to represent up to 16 million numbers. If that many documents are generated at the same time, on the same machine, and the same process, two documents can share the same object ID.
The MongoDB object ID is unique unless a certain scenario (discussed above) is reached. Therefore, as software developers, we should consider the size and complexity of the system for a trade-off between the auto-generated ID and a custom object ID.