ObjectId
An ObjectID class is available to scripts in order to facilitate working with BSON object ids used to represent unique identifiers.
ObjectId(string/date/number) Takes a hex string representation of an object id, a date or a timestamp in milliseconds.
Run this script
And you might get this
id.toString() returns the BSON id as a hexstring
id.toJSON() Used primarily by JSON.stringify(), returns the BSON id as a hexstring.
id.equals(other) Returns true if the passed in argument contains the same value as the id. The argument may be a hexstring or an ObjectID instance.
id.toDate() Returns the time the ObjectID was create as a Date value.
id.getTimestamp() Returns the number of seconds between midnight of January 1, 1970 and the time the ObjectID was created.
Last updated