MongoDB Documentation, Release 3.0.4 Changed in version 2.2: In previous versions, valueOf() returns the object. Returns the representation of the object as a hexadecimal string. The returned string is the str attribute. Changed in version 2.2: In previous versions toString() returns the hexadecimal string representation, which as of version 2.2 can be retrieved by the str property. Returns the JavaScript representation in the form of a string literal “ ObjectId(...) ”. Returns the timestamp portion of the object as a Date. Consider the following uses ObjectId() class in the mongo shell: To generate a new ObjectId, use the ObjectId() constructor with no argument: x = ObjectId() In this example, the value of x would be: ObjectId("507f1f77bcf86cd799439011") To generate a new ObjectId using the ObjectId() constructor with a unique hexadecimal string: y = ObjectId("507f191e810c19729de860ea") In this example, the value of y would be: ObjectId("507f191e810c19729de860ea") To return the timestamp of an ObjectId() object, use the getTimestamp() method as follows: ObjectId("507f191e810c19729de860ea").getTimestamp() This operation will return the following Date object: ISODate("2012-10-17T20:46:22Z") Access the str attribute of an ObjectId() object, as follows: ObjectId("507f191e810c19729de860ea").str Convert an ObjectId into a Timestamp Convert ObjectIds into Strings 177 4.4. Data Model Reference • To return the timestamp of an ObjectId() object, use the getTimestamp() method as follows: • valueOf() • toString() • getTimestamp() Examples Generate a new ObjectId