Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ObjectId

A class representation of the BSON ObjectId type.

Hierarchy

  • ObjectId

Index

Constructors

constructor

  • new ObjectId(id?: string | number | Buffer | ObjectId | ObjectIdLike): ObjectId
  • Create an ObjectId type

    Parameters

    • Optional id: string | number | Buffer | ObjectId | ObjectIdLike

      Can be a 24 character hex string, 12 byte binary Buffer, or a number.

    Returns ObjectId

Properties

_bsontype

_bsontype: "ObjectId"

generationTime

generationTime: number

id

id: Buffer

Static cacheHexString

cacheHexString: boolean

Methods

equals

  • equals(otherId: string | ObjectId | ObjectIdLike): boolean
  • Compares the equality of this ObjectId with otherID.

    Parameters

    • otherId: string | ObjectId | ObjectIdLike

      ObjectId instance to compare against.

    Returns boolean

getTimestamp

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

    Returns Date

inspect

  • inspect(): string
  • Returns string

toHexString

  • toHexString(): string
  • Returns the ObjectId id as a 24 character hex string representation

    Returns string

Static createFromHexString

  • createFromHexString(hexString: string): ObjectId
  • Creates an ObjectId from a hex string representation of an ObjectId.

    Parameters

    • hexString: string

      create a ObjectId from a passed in 24 character hexstring.

    Returns ObjectId

Static createFromTime

  • 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.

    Parameters

    • time: number

      an integer number representing a number of seconds.

    Returns ObjectId

Static generate

  • generate(time?: number): Buffer
  • Generate a 12 byte id buffer used in ObjectId's

    Parameters

    • Optional time: number

      pass in a second based timestamp.

    Returns Buffer

Static isValid

  • isValid(id: string | number | Uint8Array | ObjectId | ObjectIdLike): boolean
  • Checks if a value is a valid bson ObjectId

    Parameters

    • id: string | number | Uint8Array | ObjectId | ObjectIdLike

      ObjectId instance to validate.

    Returns boolean

Generated using TypeDoc