Skip to main content
Latest
class Bson.ObjectId
import { Bson } from "https://deno.land/x/exodus@0.1.8/deps.ts";
const { ObjectId } = Bson;

A class representation of the BSON ObjectId type.

Constructors

new
ObjectId(id?:
| string
| Buffer
| number
)

Create an ObjectId type

Properties

_bsontype: "ObjectId"
deprecated
generationTime: number

The generation time of this ObjectId instance

id: Buffer

The ObjectId bytes

Methods

equals(otherId: string | ObjectId | ObjectIdLike): boolean

Compares the equality of this ObjectId with otherID.

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

toHexString(): string

Returns the ObjectId id as a 24 character hex string representation

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.

generate(time?: number): Buffer

Generate a 12 byte id buffer used in ObjectId's

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

Checks if a value is a valid bson ObjectId