Class ObjectId

A class representation of the BSON ObjectId type.

Hierarchy

Constructors

  • Create ObjectId from a number.

    Parameters

    • inputId: number

      A number.

    Returns ObjectId

    Deprecated

    Instead, use static createFromTime() to set a numeric value for the new ObjectId.

  • Create ObjectId from a 24 character hex string.

    Parameters

    • inputId: string

      A 24 character hex string.

    Returns ObjectId

  • Create ObjectId from the BSON ObjectId type.

    Parameters

    • inputId: ObjectId

      The BSON ObjectId type.

    Returns ObjectId

  • Create ObjectId from the object type that has the toHexString method.

    Parameters

    Returns ObjectId

  • Create ObjectId from a 12 byte binary Buffer.

    Parameters

    • inputId: Uint8Array

      A 12 byte binary Buffer.

    Returns ObjectId

  • To generate a new ObjectId, use ObjectId() with no argument.

    Returns ObjectId

  • Implementation overload.

    Parameters

    • Optional inputId: string | number | Uint8Array | ObjectId | ObjectIdLike

      All input types that are used in the constructor implementation.

    Returns ObjectId

Properties

cacheHexString: boolean

Accessors

  • get _bsontype(): "ObjectId"
  • Returns "ObjectId"

  • get id(): Uint8Array
  • The ObjectId bytes

    Returns Uint8Array

Methods

  • Compares the equality of this ObjectId with otherID.

    Parameters

    • otherId: undefined | null | string | ObjectId | ObjectIdLike

      ObjectId instance to compare against.

    Returns boolean

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

    Returns Date

  • Converts to a string representation of this Id.

    Parameters

    • Optional depth: number
    • Optional options: unknown
    • Optional inspect: InspectFn

    Returns string

    return the 24 character hex string representation.

  • Returns the ObjectId id as a 24 lowercase character hex string representation

    Returns string

  • Converts to its JSON the 24 character hex string representation.

    Returns string

  • Converts the id into a 24 character hex string for printing, unless encoding is provided.

    Parameters

    • Optional encoding: "base64" | "hex"

      hex or base64

    Returns string

  • Creates an ObjectId instance from a base64 string

    Parameters

    • base64: string

    Returns 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

  • 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

  • Generate a 12 byte id buffer used in ObjectId's

    Parameters

    • Optional time: number

      pass in a second based timestamp.

    Returns Uint8Array

  • Checks if a value can be used to create a valid bson ObjectId

    Parameters

    Returns boolean

Generated using TypeDoc