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 the mongo shell:

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()
←  ObjectId.getTimestamp()ObjectId.valueOf() →

On this page

Give Feedback
© 2022 MongoDB, Inc.

About

  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2022 MongoDB, Inc.