Docs Menu

ObjectId.valueOf()

On this page

  • Example
ObjectId.valueOf()

Returns the value of the ObjectId() as a lowercase hexadecimal string. This value is the str attribute of the ObjectId() object.

The following example calls the valueOf() method on an ObjectId():

ObjectId("507c7f79bcf86cd7994f6c0e").valueOf()

This will return the following string:

507c7f79bcf86cd7994f6c0e

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

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

On this page

Give Feedback
MongoDB logo
© 2021 MongoDB, Inc.

About

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