ObjectId.toString()
On this page
This version of the documentation is archived and no longer supported. View the current documentation to learn how to upgrade your version of MongoDB server.
ObjectId.toString()
Returns the string representation of the
ObjectId()
. This string value has the format ofObjectId(...)
.
Example
The following example calls the toString()
method
on an ObjectId()
instance in mongosh
:
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()