OPTIONS

ObjectId.toString()

ObjectId.toString()
Returns:The string representation of the ObjectId() object. This value has the format of ObjectId(...).

Changed in version 2.2: In previous versions ObjectId.toString() returns the value of the ObjectId as a hexadecimal string.

In the following example, call the toString() method on an ObjectId (e.g. ObjectId("507c7f79bcf86cd7994f6c0e")):

ObjectId("507c7f79bcf86cd7994f6c0e").toString()

This will return the following string:

ObjectId("507c7f79bcf86cd7994f6c0e")

You can confirm the type of this object using the following operation:

typeof ObjectId("507c7f79bcf86cd7994f6c0e").toString()

Was this page helpful?

Yes No

Thank you for your feedback!

We're sorry! You can Report a Problem to help us improve this page.