ObjectId.toString()

On this page本页内容

ObjectId.toString()

Returns the string representation of the ObjectId(). 返回ObjectId()的字符串表示形式。This string value has the format of ObjectId(...).此字符串值的格式为ObjectId(...)

Example示例

The following example calls the toString() method on an ObjectId() instance in mongosh:以下示例在mongosh中的ObjectId()实例上调用toString()方法:

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