1+ .. _server-objectid:
2+
13==========
24ObjectId()
35==========
@@ -28,10 +30,10 @@ Description
2830 .. list-table::
2931 :header-rows: 1
3032 :widths: 20 80
31-
33+
3234 * - Input Type
3335 - Description
34-
36+
3537 * - ``hexadecimal``
3638 - Optional. A 24 character hexadecimal string value for the new
3739 ObjectId.
@@ -41,28 +43,31 @@ Description
4143 :wikipedia:`Unix epoch` to create the new timestamp.
4244
4345
44- Methods and Attributes
45- -----------------------
46+ Methods
47+ -------
4648
47- :method:`ObjectId()` has the following attribute and methods:
49+ :method:`ObjectId()` has the following methods:
4850
4951.. list-table::
5052 :header-rows: 1
5153 :widths: 30 70
5254
53- * - Attribute/Method
55+ * - Methods
5456 - Description
55-
56- * - ``str``
57- - Returns the hexadecimal string representation of the object.
57+
5858 * - :method:`ObjectId.getTimestamp()`
5959 - Returns the timestamp portion of the object as a Date.
60+
6061 * - :method:`ObjectId.toString()`
61- - Returns the JavaScript representation in the form of a string
62- literal "``ObjectId(...)``".
62+ - Returns the ObjectId as a hexadecimal string.
63+
6364 * - :method:`ObjectId.valueOf()`
64- - Returns the representation of the object as a hexadecimal
65- string. The returned string is the ``str`` attribute.
65+ - Returns ``ObjectId.self``.
66+
67+ Behavior
68+ --------
69+
70+ .. include:: /includes/reference/fact-objectid-and-mongosh.rst
6671
6772Examples
6873--------
@@ -74,40 +79,25 @@ To generate a new ObjectId, use :method:`ObjectId()` with no argument:
7479
7580.. code-block:: javascript
7681
77- x = ObjectId()
82+ newObjectId = ObjectId()
7883
79- In this example, the value of ``x `` is:
84+ In this example, the value of ``newObjectId `` is:
8085
8186.. code-block:: javascript
8287
8388 ObjectId("507f1f77bcf86cd799439011")
8489
85- Specify a Hexadecimal String
86- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
87-
88- To generate a new ObjectId using :method:`ObjectId()` with a unique
89- hexadecimal string:
90-
91- .. code-block:: javascript
92-
93- y = ObjectId("507f191e810c19729de860ea")
90+ Return a Hexadecimal String
91+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
9492
95- In this example, the value of ``y`` would be:
93+ To return the ObjectId as a hexadecimal string, use the ``toString()``
94+ method.
9695
9796.. code-block:: javascript
9897
99- ObjectId("507f191e810c19729de860ea")
98+ ObjectId("507f191e810c19729de860ea").toString()
10099
101- Access the Hexadecimal String
102- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
103-
104- Access the ``str`` attribute of an ``ObjectId()`` object, as follows:
105-
106- .. code-block:: javascript
107-
108- ObjectId("507f191e810c19729de860ea").str
109-
110- This operation will return the following hexadecimal string:
100+ The method returns:
111101
112102.. code-block:: none
113103
@@ -116,23 +106,39 @@ This operation will return the following hexadecimal string:
116106Specify an Integer String
117107~~~~~~~~~~~~~~~~~~~~~~~~~
118108
119- Generate a new ObjectId using an integer.
109+ If you want to adjust the ObjectId timestamp, use an integer to generate
110+ a new ObjectId.
120111
121112.. code-block:: javascript
122113
123114 newObjectId = ObjectId(32)
124115
125- The ObjectId resembles:
116+ The ObjectId value resembles:
126117
127118.. code-block:: javascript
128119
129120 ObjectId("00000020f51bb4362eee2a4d")
130121
131- The first four bytes of the ObjectId are the number of seconds since
132- the :wikipedia:`Unix epoch`. In this example ``32`` seconds,
133- represented in hexadecimal as ``00000020``, are added. A five byte
134- random element and a three byte counter make up the rest of the
135- ObjectId.
122+ The example ObjectId consists of:
123+
124+ - A four byte time stamp, ``00000020``
125+ - A five byte random element, ``f51bb4362e``
126+ - A three byte counter, ``ee2a4d``
127+
128+ The first four bytes of the ObjectId are the number of seconds since the
129+ :wikipedia:`Unix epoch`. In this example, the ObjectId timestamp is
130+ ``00000020`` which is ``32`` in hexadecimal.
131+
132+ Specify a Hexadecimal String
133+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
134+
135+ If you want to use a hexadecimal string to specify an ObjectId, pass a
136+ unique, 24 character hexadecimal value when you call
137+ :method:`ObjectId()`:
138+
139+ .. code-block:: javascript
140+
141+ newObjectId = ObjectId("507f191e810c19729de860ea")
136142
137143.. seealso::
138144
0 commit comments