Kotlin BSON • Multiplatform abstraction for different BSON implementations • opensavvy.ktmongo.bson.types • ObjectIdGenerator
ObjectIdGenerator¶
interface ObjectIdGenerator
An object responsible for generating new ObjectId
instances.
This object is similar to kotlin.time.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.
To get the real generator instance, see the database's opensavvy.ktmongo.bson.BsonContext
.
Inheritors¶
Types¶
Companion
¶
object Companion
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.
Hardcoded
¶
@ExperimentalTime
class Hardcoded(ids: Iterator<ObjectId>) : ObjectIdGenerator
Hardcoded ObjectId
generator with a deterministic input sequence.
Functions¶
newId
¶
@ExperimentalTime
abstract fun newId(): ObjectId
Creates a new instance of an ObjectId
.