I created timestamps one by one and got them:
ObjectId("586a291570b9a181fc2f61ba").getTimestamp(); ISODate("2017-01-02T10:19:01Z")
The following timestamp:
ObjectId("586a291570b9a181fc2f61bc").getTimestamp(); ISODate("2017-01-02T10:19:01Z")
You will notice that although the only granularity printed by getTimestamp() is in seconds, there is another granularity that causes the ObjectId line to change, although both are at 01 second.
Reason :
BSON has a special timestamp type for internal MongoDB use and is not associated with the regular Date type. Timestamp values are a 64 bit value where: the first 32 bits are a time_t value (seconds since the Unix epoch) the second 32 bits are an incrementing ordinal for operations within a given second. Within a single mongod instance, timestamp values are always unique.
Thus, the true granularity refers to the 32-bit order created by MongoDB. It is associated with operations within a second , not the time value, so you do not get it in milliseconds.
source share