ObjectId
A 12-byte (probably) unique object identifier.
ObjectIds are similar to a GUID or a UUID, and can be used to uniquely identify objects without a centralized ID generator. An ObjectID consists of:
- A 4 byte timestamp measuring the creation time of the ObjectId in seconds since the Unix epoch.
- A 5 byte random value
- A 3 byte counter, initialized to a random value.
ObjectIds are intended to be fast to generate. Sorting by an ObjectId field will typically result in the objects being sorted in creation order.
-
Creates a new zero-initialized ObjectId.
-
Creates a new randomly-initialized ObjectId.
-
Creates a new ObjectId from the given 24-byte hexadecimal string.
Throws if the string is not 24 characters or contains any characters other than 0-9a-fA-F.
-
Creates a new ObjectId using the given date, machine identifier, process identifier.
-
Creates a new ObjectId from the given 24-byte hexadecimal static string.
Aborts if the string is not 24 characters or contains any characters other than 0-9a-fA-F. Use the initializer which takes a String to handle invalid strings at runtime.
-
Creates a new ObjectId by decoding from the given decoder.
This initializer throws an error if reading from the decoder fails, or if the data read is corrupted or otherwise invalid.
-
Encodes this ObjectId into the given encoder.
This function throws an error if the given encoder is unable to encode a string.
-
Returns a Boolean value indicating whether the value of the first argument is less than that of the second argument.
-
Returns a Boolean value indicating whether the ObjectId of the first argument is less than or equal to that of the second argument.
-
Returns a Boolean value indicating whether the ObjectId of the first argument is greater than or equal to that of the second argument.
-
Returns a Boolean value indicating whether the ObjectId of the first argument is greater than that of the second argument.