@@ -12,28 +12,44 @@ ObjectId.toString()
12
12
13
13
.. method:: ObjectId.toString()
14
14
15
- Returns the string representation of the :method:`ObjectId()`. This
16
- string value has the format of ``ObjectId(...)``.
15
+ Returns the string representation of the :method:`ObjectId()`.
17
16
18
17
Example
19
18
-------
20
19
21
- The following example calls the :method:`~ObjectId.toString()` method
22
- on an :method:`ObjectId()` instance in the :binary:`~bin.mongo` shell:
20
+ The following example:
21
+
22
+ - Generates a new :method:`ObjectId()` and stores it in the
23
+ variable ``myObjectId``.
24
+
25
+ - Creates a string representation of ``myObjectId`` using
26
+ the :method:`toString()<ObjectId.toString()>` method.
27
+
28
+ - Stores the string representation in the variable ``myObjectIdString``.
29
+
30
+ Run the following commands in :binary:`mongosh`:
31
+
32
+ .. code-block:: javascript
33
+
34
+ myObjectId = ObjectId("507c7f79bcf86cd7994f6c0e")
35
+ myObjectIdString = myObjectId.toString()
36
+
37
+ The operation returns the following string:
23
38
24
39
.. code-block:: javascript
40
+ :copyable: false
25
41
26
- ObjectId(" 507c7f79bcf86cd7994f6c0e").toString()
42
+ 507c7f79bcf86cd7994f6c0e
27
43
28
- This will return the following string :
44
+ To confirm the type of ``myObjectIdString``, use the ``typeof`` JavaScript operator :
29
45
30
46
.. code-block:: javascript
31
47
32
- ObjectId("507c7f79bcf86cd7994f6c0e")
48
+ typeof myObjectIdString
33
49
34
- You can confirm the type of this object using the following
35
- operation:
50
+ The operation returns the following:
36
51
37
52
.. code-block:: javascript
53
+ :copyable: false
38
54
39
- typeof ObjectId("507c7f79bcf86cd7994f6c0e").toString()
55
+ string
0 commit comments