Skip to content

Kotlin BSON • Multiplatform abstraction for different BSON implementationsopensavvy.ktmongo.bson.typesObjectIdGeneratorDefault

Default

@ExperimentalAtomicApi
@ExperimentalTime
class Default(clock: Clock = Clock.System, random: Random = Random, processId: Long = random.nextLong(0, ObjectId.PROCESS_ID_BOUND)) : ObjectIdGenerator

The default ObjectIdGenerator, implementing the MongoDB ObjectId generation algorithm.

Note that it isn't guaranteed that IDs are generated monotonically: it is possible that an ID is lesser (according to ObjectId.compareTo) than one generated previously, but only if both were generated during the same second.

However, it is guaranteed until the year 2016 that an ID is always strictly greater than one generated in a previous second.

Constructors

Default

constructor(clock: Clock = Clock.System, random: Random = Random, processId: Long = random.nextLong(0, ObjectId.PROCESS_ID_BOUND))

Functions

newId

open override fun newId(): ObjectId

Creates a new instance of an ObjectId.