Docs Menu

ObjectId.toString()

On this page

  • Example
ObjectId.toString()

Returns the string representation of the ObjectId(). This string value has the format of ObjectId(...).

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()

On this page

Give Feedback
MongoDB logo
© 2021 MongoDB, Inc.

About

  • Careers
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2021 MongoDB, Inc.