@@ -15,34 +15,30 @@ ObjectId
15
15
Description
16
16
-----------
17
17
18
- .. method:: ObjectId(<hexadecimal >)
18
+ .. method:: ObjectId(<value >)
19
19
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:
22
22
23
23
.. include:: /includes/fact-ObjectId-construct.rst
24
24
25
- :method:`ObjectId()` can accept the following parameter :
25
+ :method:`ObjectId()` can accept one of the following inputs :
26
26
27
27
28
28
.. list-table::
29
29
:header-rows: 1
30
- :widths: 20 20 80
31
-
32
- * - Field
33
-
34
- - Type
30
+ :widths: 20 80
35
31
32
+ * - Input Type
36
33
- Description
37
34
38
35
* - ``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.
46
42
47
43
48
44
Methods and Attributes
@@ -58,20 +54,13 @@ Methods and Attributes
58
54
- Description
59
55
60
56
* - ``str``
61
-
62
57
- Returns the hexadecimal string representation of the object.
63
-
64
58
* - :method:`ObjectId.getTimestamp()`
65
-
66
59
- Returns the timestamp portion of the object as a Date.
67
-
68
60
* - :method:`ObjectId.toString()`
69
-
70
61
- Returns the JavaScript representation in the form of a string
71
62
literal "``ObjectId(...)``".
72
-
73
63
* - :method:`ObjectId.valueOf()`
74
-
75
64
- Returns the representation of the object as a hexadecimal
76
65
string. The returned string is the ``str`` attribute.
77
66
@@ -87,7 +76,7 @@ To generate a new ObjectId, use :method:`ObjectId()` with no argument:
87
76
88
77
x = ObjectId()
89
78
90
- In this example, the value of ``x`` would be :
79
+ In this example, the value of ``x`` is :
91
80
92
81
.. code-block:: javascript
93
82
@@ -124,6 +113,27 @@ This operation will return the following hexadecimal string:
124
113
125
114
507f191e810c19729de860ea
126
115
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
+
127
137
.. seealso::
128
138
129
139
:ref:`ObjectId BSON Type <objectid>`
0 commit comments