ObjectId.toString()

  • ObjectId.toString()
  • Returns the string representation of the ObjectId(). Thisstring value has the format of ObjectId(…).

Example

The following example calls the toString() methodon an ObjectId() instance in the mongo shell:

  1. ObjectId("507c7f79bcf86cd7994f6c0e").toString()

This will return the following string:

  1. ObjectId("507c7f79bcf86cd7994f6c0e")

You can confirm the type of this object using the followingoperation:

  1. typeof ObjectId("507c7f79bcf86cd7994f6c0e").toString()