Skip to content

Commit aa2669e

Browse files
committed
WRITING-1600: MWS integration
1 parent 57ff0c9 commit aa2669e

File tree

5 files changed

+101
-105
lines changed

5 files changed

+101
-105
lines changed

source/includes/fact-id-field.rst

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
In MongoDB, documents stored in a collection require a unique
2-
:term:`_id` field that acts as a :term:`primary key`. If the ``_id``
3-
field is unspecified in the documents, MongoDB uses :ref:`ObjectIds
4-
<objectid>` as the default value for the ``_id`` field; i.e. if a
5-
document does not contain a top-level ``_id`` field during an insert,
6-
the MongoDB driver adds the ``_id`` field that holds an :ref:`objectid`.
1+
In MongoDB, each document stored in a collection requires a unique
2+
:term:`_id` field that acts as a :term:`primary key`. If an inserted
3+
document omits the ``_id`` field, the MongoDB driver automatically
4+
generates an :ref:`objectid` for the ``_id`` field.
75

8-
In addition, if the :program:`mongod` receives a document to insert
9-
that does not contain an ``_id`` field (e.g. through an update
10-
operation with an :ref:`upsert option <upsert-parameter>`)
11-
:program:`mongod` will add the ``_id`` field that holds an ObjectId.
6+
This also applies to documents inserted through update
7+
operations with :ref:`upsert: true <upsert-parameter>`.

source/includes/fact-mws.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.. raw:: html
2+
3+
<iframe class="mws-root" allowfullscreen sandbox="allow-scripts allow-same-origin" width=600 height=280 src="https://mws.mongodb.com/"></iframe>

source/reference/method/db.collection.insertMany.txt

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Definition
1616
.. method:: db.collection.insertMany()
1717

1818
.. versionadded:: 3.2
19-
19+
2020
Inserts multiple documents into a collection.
2121

2222
The :method:`~db.collection.insertMany()` method has the following
@@ -35,28 +35,28 @@ Definition
3535
.. include:: /includes/apiargs/method-db.collection.insertMany-param.rst
3636

3737
:returns:
38-
38+
3939
A document containing:
4040

41-
- A boolean ``acknowledged`` as ``true`` if the operation ran with
41+
- A boolean ``acknowledged`` as ``true`` if the operation ran with
4242
:term:`write concern` or ``false`` if write concern was disabled
4343

4444
- An array of ``_id`` for each successfully inserted documents
4545

4646
Behaviors
4747
---------
4848

49-
Given an array of documents, :method:`~db.collection.insertMany()`
49+
Given an array of documents, :method:`~db.collection.insertMany()`
5050
inserts each document in the array into the collection.
5151

5252
Execution of Operations
5353
~~~~~~~~~~~~~~~~~~~~~~~
5454

5555
By default documents are inserted in order.
5656

57-
If ``ordered`` is set to false, documents are inserted in an unordered
58-
format and may be reordered by :program:`mongod` to increase performance.
59-
Applications should not depend on ordering of inserts if using an unordered
57+
If ``ordered`` is set to false, documents are inserted in an unordered
58+
format and may be reordered by :program:`mongod` to increase performance.
59+
Applications should not depend on ordering of inserts if using an unordered
6060
:method:`~db.collection.insertMany()`.
6161

6262
.. include:: /includes/fact-bulkwrite-operation-batches.rst
@@ -67,13 +67,13 @@ Applications should not depend on ordering of inserts if using an unordered
6767
Collection Creation
6868
~~~~~~~~~~~~~~~~~~~
6969

70-
If the collection does not exist, then :method:`~db.collection.insertMany()`
70+
If the collection does not exist, then :method:`~db.collection.insertMany()`
7171
creates the collection on successful write.
7272

7373
``_id`` Field
7474
~~~~~~~~~~~~~
7575

76-
If the document does not specify an :term:`_id` field, then :program:`mongod`
76+
If the document does not specify an :term:`_id` field, then :program:`mongod`
7777
adds the ``_id`` field and assign a unique
7878
:method:`ObjectId` for the document. Most
7979
drivers create an ObjectId and insert the ``_id`` field, but the
@@ -100,16 +100,18 @@ Error Handling
100100

101101
Inserts throw a ``BulkWriteError`` exception.
102102

103-
Excluding :doc:`/reference/write-concern` errors, ordered operations stop
104-
after an error, while unordered operations continue to process any
103+
Excluding :doc:`/reference/write-concern` errors, ordered operations stop
104+
after an error, while unordered operations continue to process any
105105
remaining write operations in the queue.
106106

107-
Write concern errors are displayed in the ``writeConcernErrors`` field, while
108-
all other errors are displayed in the ``writeErrors`` field. If an error is
109-
encountered, the number of successful write operations are displayed instead
110-
of a list of inserted _ids. Ordered operations display the single error
107+
Write concern errors are displayed in the ``writeConcernErrors`` field, while
108+
all other errors are displayed in the ``writeErrors`` field. If an error is
109+
encountered, the number of successful write operations are displayed instead
110+
of a list of inserted _ids. Ordered operations display the single error
111111
encountered while unordered operations display each error in an array.
112112

113+
.. _insertMany-examples:
114+
113115
Examples
114116
--------
115117

@@ -119,13 +121,13 @@ collection.
119121
Insert Several Document without Specifying an ``_id`` Field
120122
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
121123

122-
The following example uses :method:`db.collection.insertMany()` to insert
124+
The following example uses :method:`db.collection.insertMany()` to insert
123125
documents that do not contain the ``_id`` field:
124126

125127
.. code-block:: javascript
126128

127129
try {
128-
db.products.insertMany( [
130+
db.products.insertMany( [
129131
{ item: "card", qty: 15 },
130132
{ item: "envelope", qty: 20 },
131133
{ item: "stamps" , qty: 30 }
@@ -147,7 +149,7 @@ The operation returns the following document:
147149
]
148150
}
149151

150-
Because the documents did not include ``_id``,
152+
Because the documents did not include ``_id``,
151153
:program:`mongod` creates and adds the ``_id`` field for each document and
152154
assigns it a unique :method:`ObjectId` value.
153155

@@ -156,8 +158,8 @@ assigns it a unique :method:`ObjectId` value.
156158
Insert Several Document Specifying an ``_id`` Field
157159
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
158160

159-
The following example/operation uses :method:`~db.collection.insertMany()` to
160-
insert documents that include the ``_id`` field. The value of ``_id`` must be
161+
The following example/operation uses :method:`~db.collection.insertMany()` to
162+
insert documents that include the ``_id`` field. The value of ``_id`` must be
161163
unique within the collection to avoid a duplicate key error.
162164

163165
.. code-block:: javascript
@@ -178,8 +180,8 @@ The operation returns the following document:
178180

179181
{ "acknowledged" : true, "insertedIds" : [ 10, 11, 12 ] }
180182

181-
Inserting a duplicate value for any key that is part of a :term:`unique
182-
index`, such as ``_id``, throws an exception. The following attempts to insert
183+
Inserting a duplicate value for any key that is part of a :term:`unique
184+
index`, such as ``_id``, throws an exception. The following attempts to insert
183185
a document with a ``_id`` value that already exists:
184186

185187
.. code-block:: javascript
@@ -193,11 +195,11 @@ a document with a ``_id`` value that already exists:
193195
} catch (e) {
194196
print (e);
195197
}
196-
198+
197199
Since ``_id: 13`` already exists, the following exception is thrown:
198-
200+
199201
.. code-block:: javascript
200-
202+
201203
BulkWriteError({
202204
"writeErrors" : [
203205
{
@@ -220,19 +222,19 @@ Since ``_id: 13`` already exists, the following exception is thrown:
220222
"upserted" : [ ]
221223
})
222224

223-
Note that one document was inserted: The first document of ``_id: 13`` will
224-
insert successfully, but the second insert will fail. This will also stop
225+
Note that one document was inserted: The first document of ``_id: 13`` will
226+
insert successfully, but the second insert will fail. This will also stop
225227
additional documents left in the queue from being inserted.
226228

227-
With ``ordered`` to ``false``, the insert operation would continue with any
229+
With ``ordered`` to ``false``, the insert operation would continue with any
228230
remaining documents.
229231

230232
Unordered Inserts
231233
~~~~~~~~~~~~~~~~~
232234

233-
The following attempts to insert multiple documents with ``_id`` field and
234-
``ordered: false``. The array of documents contains two documents with
235-
duplicate ``_id`` fields.
235+
The following attempts to insert multiple documents with ``_id`` field and
236+
``ordered: false``. The array of documents contains two documents with
237+
duplicate ``_id`` fields.
236238

237239
.. code-block:: javascript
238240

@@ -253,7 +255,7 @@ duplicate ``_id`` fields.
253255
The operation throws the following exception:
254256

255257
.. code-block:: javascript
256-
258+
257259
BulkWriteError({
258260
"writeErrors" : [
259261
{
@@ -286,22 +288,22 @@ The operation throws the following exception:
286288
"upserted" : [ ]
287289
})
288290

289-
While the document with ``item: "medium box"`` and ``item: "tape"``
290-
failed to insert due to duplicate ``_id`` values,
291+
While the document with ``item: "medium box"`` and ``item: "tape"``
292+
failed to insert due to duplicate ``_id`` values,
291293
``nInserted`` shows that the remaining 5 documents were inserted.
292294

293295
.. _insertMany-using-write-concern:
294296

295297
Using Write Concern
296298
~~~~~~~~~~~~~~~~~~~~~~~~
297299

298-
Given a three member replica set, the following operation specifies a
300+
Given a three member replica set, the following operation specifies a
299301
``w`` of ``majority`` and ``wtimeout`` of ``100``:
300302

301303
.. code-block:: javascript
302304

303305
try {
304-
db.products.insertMany(
306+
db.products.insertMany(
305307
[
306308
{ _id: 10, item: "large box", qty: 20 },
307309
{ _id: 11, item: "small box", qty: 55 },
@@ -313,7 +315,7 @@ Given a three member replica set, the following operation specifies a
313315
print (e);
314316
}
315317

316-
If the primary and at least one secondary acknowledge each write operation
318+
If the primary and at least one secondary acknowledge each write operation
317319
within 100 milliseconds, it returns:
318320

319321
.. code-block:: javascript
@@ -327,9 +329,9 @@ within 100 milliseconds, it returns:
327329
]
328330
}
329331

330-
If the total time required for all required nodes in the replica set to
331-
acknowledge the write operation is greater than ``wtimeout``,
332-
the following ``writeConcernError`` is displayed when the ``wtimeout`` period
332+
If the total time required for all required nodes in the replica set to
333+
acknowledge the write operation is greater than ``wtimeout``,
334+
the following ``writeConcernError`` is displayed when the ``wtimeout`` period
333335
has passed.
334336

335337
This operation returns:

source/reference/method/db.collection.insertOne.txt

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ Definition
3737

3838
A document containing:
3939

40-
- A boolean ``acknowledged`` as ``true`` if the operation ran with
40+
- A boolean ``acknowledged`` as ``true`` if the operation ran with
4141
:term:`write concern` or ``false`` if write concern was disabled.
4242

43-
- A field ``insertedId`` with the ``_id`` value of the
43+
- A field ``insertedId`` with the ``_id`` value of the
4444
inserted document.
4545

4646
Behaviors
@@ -55,7 +55,7 @@ If the collection does not exist, then the
5555
``_id`` Field
5656
~~~~~~~~~~~~~
5757

58-
If the document does not specify an :term:`_id` field, then :program:`mongod`
58+
If the document does not specify an :term:`_id` field, then :program:`mongod`
5959
will add the ``_id`` field and assign a unique
6060
:method:`ObjectId` for the document before inserting. Most
6161
drivers create an ObjectId and insert the ``_id`` field, but the
@@ -77,13 +77,14 @@ Explainability
7777
Error Handling
7878
~~~~~~~~~~~~~~
7979

80-
On error, :method:`~db.collection.insertOne()` throws either a ``writeError``
80+
On error, :method:`~db.collection.insertOne()` throws either a ``writeError``
8181
or ``writeConcernError`` exception.
8282

83+
.. _insertOne-examples:
84+
8385
Examples
8486
--------
8587

86-
8788
Insert a Document without Specifying an ``_id`` Field
8889
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8990

@@ -107,9 +108,9 @@ The operation returns the following document:
107108
"acknowledged" : true,
108109
"insertedId" : ObjectId("56fc40f9d735c28df206d078")
109110
}
110-
111111

112-
Because the documents did not include ``_id``,
112+
113+
Because the documents did not include ``_id``,
113114
:program:`mongod` creates and adds the ``_id`` field and
114115
assigns it a unique :method:`ObjectId` value.
115116

@@ -136,9 +137,9 @@ The operation returns the following:
136137
.. code-block:: javascript
137138

138139
{ "acknowledged" : true, "insertedId" : 10 }
139-
140-
Inserting an duplicate value for any key that is part of a :term:`unique
141-
index`, such as ``_id``, throws an exception. The following attempts to insert
140+
141+
Inserting an duplicate value for any key that is part of a :term:`unique
142+
index`, such as ``_id``, throws an exception. The following attempts to insert
142143
a document with a ``_id`` value that already exists:
143144

144145
.. code-block:: javascript
@@ -150,9 +151,9 @@ a document with a ``_id`` value that already exists:
150151
}
151152

152153
Since ``_id: 10`` already exists, the following exception is thrown:
153-
154+
154155
.. code-block:: javascript
155-
156+
156157
WriteError({
157158
"index" : 0,
158159
"code" : 11000,
@@ -169,7 +170,7 @@ Since ``_id: 10`` already exists, the following exception is thrown:
169170
Increase Write Concern
170171
~~~~~~~~~~~~~~~~~~~~~~
171172

172-
Given a three member replica set, the following operation specifies a
173+
Given a three member replica set, the following operation specifies a
173174
``w`` of ``majority``, ``wtimeout`` of ``100``:
174175

175176
.. code-block:: javascript
@@ -183,7 +184,7 @@ Given a three member replica set, the following operation specifies a
183184
print (e);
184185
}
185186

186-
If the acknowledgement takes longer than the ``wtimeout`` limit, the following
187+
If the acknowledgement takes longer than the ``wtimeout`` limit, the following
187188
exception is thrown:
188189

189190
.. code-block:: javascript

0 commit comments

Comments
 (0)