Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/hex/src/data/deps.ts>mongo.Bson.ObjectId

An ecosystem delivering practices, philosophy and portability.
Go to Latest
class mongo.Bson.ObjectId
Re-export
import { mongo } from "https://deno.land/x/hex@0.5.15/src/data/deps.ts";
const { ObjectId } = mongo.Bson;

A class representation of the BSON ObjectId type.

Constructors

new
ObjectId(inputId?:
| string
| number
| Uint8Array
)

Create an ObjectId type

Properties

_bsontype: string
id: Uint8Array

The ObjectId bytes

Methods

equals(otherId: string | ObjectId): boolean

Compares the equality of this ObjectId with otherID.

Returns the generation date (accurate up to the second) that this ID was generated.

toExtendedJSON(): ObjectIdExtended
toHexString(): string

Returns the ObjectId id as a 24 character hex string representation

toJSON(): string

Converts to its JSON the 24 character hex string representation.

toString(): string

Converts the id into a 24 character hex string for printing

Static Properties

cacheHexString: boolean

Static Methods

createFromHexString(hexString: string): ObjectId

Creates an ObjectId from a hex string representation of an ObjectId.

createFromTime(time: number): ObjectId

Creates an ObjectId from a second based number, with the rest of the ObjectId zeroed out. Used for comparisons or sorting the ObjectId.

fromExtendedJSON(doc: ObjectIdExtended): ObjectId
generate(time?: number): Uint8Array

Generate a 12 byte id buffer used in ObjectId's

isValid(id:
| string
| number
| Uint8Array
): boolean

Checks if a value is a valid bson ObjectId