Skip to content

ObjectIdGenerator

interface ObjectIdGenerator

An object responsible for generating new ObjectId instances.

This object is similar to Clock: a Clock is a way to generate Instant instances, and services that need to generate instants should receive a clock via dependency injection. Similarly, services that generate IDs should get a generator via dependency injection.

Each collection has its own ObjectIdGenerator instance, set by default by the driver.

Inheritors

Types

Companion

object Companion

Default

@ExperimentalAtomicApi
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.

Hardcoded

Hardcoded ObjectId generator with a deterministic input sequence.

Functions

newId

abstract fun newId(): ObjectId

Creates a new instance of an ObjectId.

Throws

NoSuchElementException

If the generator is not able to generate more IDs.