MongoDB Driver API for Node.js (original) (raw)

Class: ObjectID

ObjectID

Create a new ObjectID instance

Name Type Description
id string|number Can be a 24 byte hex string, 12 byte binary string or a Number.
Properties:
Name Type Description
generationTime number The generation time of this ObjectId instance
Returns:

of ObjectID.

Methods

staticObjectID.createFromHexString(hexString){ObjectID}

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

Name Type Description
hexString string create a ObjectID from a passed in 24 byte hexstring.
Returns:

the created ObjectID

staticObjectID.createFromTime(time){ObjectID}

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

Name Type Description
time number an integer number representing a number of seconds.
Returns:

the created ObjectID

staticObjectID.isValid(){boolean}

Checks if a value is a valid bson ObjectId

Returns:

true if the value is a valid bson ObjectId, return false otherwise.

equals(otherID){boolean}

Compares the equality of this ObjectID with otherID.

Name Type Description
otherID object ObjectID instance to compare against.
Returns:

result of comparing two ObjectID's

generate(time){Buffer}

Generate a 12 byte id buffer used in ObjectID's

Name Type Description
time number optional optional parameter allowing to pass in a second based timestamp.
Returns:

the 12 byte id buffer string.

getTimestamp(){date}

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

Returns:

generation date

toHexString(){string}

Return the ObjectID id as a 24 byte hex string representation

Returns:

the 24 byte hex string representation.