Docs Menu

Docs HomeMongoDB Manual

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

On this page

Share Feedback
© 2023 MongoDB, Inc.

About

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