Skip to content

Commit 6ec4eb6

Browse files
author
Dave
authored
DOCS-17365 ObjectId with integer arg (#776)
* DOCS-17365 ObjectId with integer arg * Staging updates * Review feedback * Review feedback * Staging updates * Review feedback * Review feedback * review feedback
1 parent 71c11d5 commit 6ec4eb6

File tree

2 files changed

+45
-31
lines changed

2 files changed

+45
-31
lines changed

source/includes/fact-ObjectId-construct.rst

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
- a 4-byte *timestamp value*, representing the ObjectId's creation,
2-
measured in seconds since the Unix epoch
1+
- A 4-byte timestamp, representing the ObjectId's creation, measured
2+
in seconds since the Unix epoch.
33

4-
- a 5-byte *random value* generated once per process. This random value
4+
- A 5-byte random value generated once per process. This random value
55
is unique to the machine and process.
66

7-
- a 3-byte *incrementing counter*, initialized to a random value
7+
- A 3-byte incrementing counter, initialized to a random value.
8+
9+
While the BSON format itself is little-endian, the timestamp and
10+
counter values are big-endian, the most significant bytes appear first
11+
in the byte sequence.
12+
13+
If an integer value is used to create an ObjectId, the integer replaces
14+
the timestamp.
815

9-
While the BSON format itself is little-endian, the *timestamp* and
10-
*counter* values are big-endian, with the most significant bytes
11-
appearing first in the byte sequence.

source/reference/method/ObjectId.txt

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,30 @@ ObjectId
1515
Description
1616
-----------
1717

18-
.. method:: ObjectId(<hexadecimal>)
18+
.. method:: ObjectId(<value>)
1919

20-
Returns a new :ref:`objectid` value. The 12-byte :ref:`objectid`
21-
value consists of:
20+
Returns a new :ref:`objectid`. The 12-byte :ref:`objectid` consists
21+
of:
2222

2323
.. include:: /includes/fact-ObjectId-construct.rst
2424

25-
:method:`ObjectId()` can accept the following parameter:
25+
:method:`ObjectId()` can accept one of the following inputs:
2626

2727

2828
.. list-table::
2929
:header-rows: 1
30-
:widths: 20 20 80
31-
32-
* - Field
33-
34-
- Type
30+
:widths: 20 80
3531

32+
* - Input Type
3633
- Description
3734

3835
* - ``hexadecimal``
39-
40-
- String
41-
42-
- Optional. A 24 character hexadecimal string value for the new ObjectId.
43-
44-
45-
36+
- Optional. A 24 character hexadecimal string value for the new
37+
ObjectId.
38+
39+
* - ``integer``
40+
- Optional. The integer value, in seconds, is added to the
41+
:wikipedia:`Unix epoch` to create the new timestamp.
4642

4743

4844
Methods and Attributes
@@ -58,20 +54,13 @@ Methods and Attributes
5854
- Description
5955

6056
* - ``str``
61-
6257
- Returns the hexadecimal string representation of the object.
63-
6458
* - :method:`ObjectId.getTimestamp()`
65-
6659
- Returns the timestamp portion of the object as a Date.
67-
6860
* - :method:`ObjectId.toString()`
69-
7061
- Returns the JavaScript representation in the form of a string
7162
literal "``ObjectId(...)``".
72-
7363
* - :method:`ObjectId.valueOf()`
74-
7564
- Returns the representation of the object as a hexadecimal
7665
string. The returned string is the ``str`` attribute.
7766

@@ -87,7 +76,7 @@ To generate a new ObjectId, use :method:`ObjectId()` with no argument:
8776

8877
x = ObjectId()
8978

90-
In this example, the value of ``x`` would be:
79+
In this example, the value of ``x`` is:
9180

9281
.. code-block:: javascript
9382

@@ -124,6 +113,27 @@ This operation will return the following hexadecimal string:
124113

125114
507f191e810c19729de860ea
126115

116+
Specify an Integer String
117+
~~~~~~~~~~~~~~~~~~~~~~~~~
118+
119+
Generate a new ObjectId using an integer.
120+
121+
.. code-block:: javascript
122+
123+
newObjectId = ObjectId(32)
124+
125+
The ObjectId resembles:
126+
127+
.. code-block:: javascript
128+
129+
ObjectId("00000020f51bb4362eee2a4d")
130+
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.
136+
127137
.. seealso::
128138

129139
:ref:`ObjectId BSON Type <objectid>`

0 commit comments

Comments
 (0)