Skip to content

Commit e712103

Browse files
committed
DOCS-617 minor edits to write-operations
1 parent 9e4a9d1 commit e712103

File tree

1 file changed

+86
-91
lines changed

1 file changed

+86
-91
lines changed

draft/core/write-operations.txt

Lines changed: 86 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@ Write Operations
66

77
All operations that create or modify data in the MongoDB instance are
88
write operations. MongoDB represents data as :term:`BSON documents
9-
<document>` stored in a collection :term:`collections
10-
<collection>`. Write operations target a single collection and are
11-
atomic on the level of a single document: no single write operation
12-
can atomically affect more than one document or more than one
13-
collection.
9+
<document>` stored in :term:`collections <collection>`. Write
10+
operations target a single collection and are atomic on the level of a
11+
single document: no single write operation can atomically affect more
12+
than one document or more than one collection.
1413

15-
This document describes the syntax of all write operations in MongoDB,
16-
and describes their operation, and strategies increasing the
17-
efficiency of writes in applications.
14+
This document introduces the write operators available in MongoDB as
15+
well as presents strategies to increase the efficiency of writes in
16+
applications.
1817

1918
.. index:: write operators
2019
.. _write-operations-operators:
@@ -29,8 +28,8 @@ database, see the following pages:
2928
- :doc:`/applications/update`
3029
- :doc:`/applications/delete`
3130

32-
For information on specific methods in the :program:`mongo` shell used
33-
for write operations, see the following:
31+
For information on specific methods used to perform write operations in the
32+
:program:`mongo` shell, see the following:
3433

3534
- :method:`db.collection.insert()`
3635
- :method:`db.collection.update()`
@@ -54,43 +53,42 @@ Write Concern
5453
Operational Considerations and Write Concern
5554
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5655

57-
Clients issue all write operations with some level of :term:`Write
58-
concern <write concern>`, which describes level of concern or the kind
59-
of guarantee the server will provide in its response to a write
60-
operation. Consider the following levels of conceptual write concern:
56+
Clients issue write operations with some level of :term:`write
57+
concern`, which describes the level of concern or the kind of
58+
guarantee the server will provide in its response to a write operation.
59+
Consider the following levels of conceptual write concern:
6160

6261
- *none*: Write operations are not acknowledged, and may be lost if
6362
there is a connection error that the client is not yet aware of, or
6463
if the :program:`mongod` produces an exception (e.g. a duplicate key
6564
exception for :ref:`unique indexes <index-type-unique>`.) While this
6665
operation is efficient because it does not require the database to
6766
respond to every write operation, it also incurs a significant risk
68-
about the persistence and durability of the data.
67+
in regards to the persistence and durability of the data.
6968

7069
Before the releases outlined in :ref:`driver-write-concern-change`,
7170
this was the default write concern.
7271

73-
- *receipt acknowledgment*: The :program:`mongod` will confirm
72+
- *receipt acknowledgment*: The :program:`mongod` will confirm the
7473
receipt of the write operation, allowing the client to catch
7574
network, duplicate key, and other exceptions. After the releases
7675
outlined in :ref:`driver-write-concern-change`, this is the default
7776
write concern. [#default-write-concern]_
7877

7978
- *journal commit*: The :program:`mongod` will confirm the write
80-
operation only after it has written operation to the
81-
:term:`journal`. This confirms that the write operation can survive
82-
a :program:`mongod` shutdown and ensures that the write operation is
83-
durable.
84-
85-
While receipt acknowledgment provides the fundamental basis
86-
for write concern, without requiring a journal commit in the write
87-
concern, there is an up-to 100 millisecond window between journal
88-
commits where the write operation is not fully durable. Require
89-
journal commit as part of the write concern to provide this
90-
durability guarantee.
91-
92-
:term:`Replica sets <replica set>` add an additional layer of
93-
consideration for write concern. Basic write concerns level affect the
79+
operation only after it has written the operation to the
80+
:term:`journal`. This confirms that the write operation can survive a
81+
:program:`mongod` shutdown and ensures that the write operation is
82+
durable.
83+
84+
While *receipt acknowledgment* without *journal commit* provides the
85+
fundamental basis for write concern, there is an up-to 100
86+
millisecond window between journal commits where the write operation
87+
is not fully durable. Require *journal commit* as part of the write
88+
concern to provide this durability guarantee.
89+
90+
:term:`Replica sets <replica set>` present an additional layer of
91+
consideration for write concern. Basic write concern level affect the
9492
write operation on only one :program:`mongod` instance. The ``w``
9593
argument to :dbcommand:`getLastError` makes it possible to guarantee
9694
that the write operation has propagated to the members of a replica
@@ -99,13 +97,12 @@ set. See the :ref:`Write Concern for Replica Sets
9997

10098

10199
.. [#default-write-concern] The default write concern is to call
102-
:dbcommand:`getLastError` with no arguments. For replica sets with
103-
:data:`getLastErrorDefaults <settings.getLastErrorDefaults>`
104-
settings, the default write concern will be whatever
105-
:data:`getLastErrorDefaults <settings.getLastErrorDefaults>`
106-
defines. If :data:`getLastErrorDefaults <settings.getLastErrorDefaults>`
107-
defines no default write concern, :dbcommand:`getLastError` will
108-
provide basic receipt acknowledgment.
100+
:dbcommand:`getLastError` with no arguments. For replica sets, you
101+
can define the default write concern settings in the
102+
:data:`getLastErrorDefaults <settings.getLastErrorDefaults>`. If
103+
:data:`getLastErrorDefaults <settings.getLastErrorDefaults>` does
104+
not define a default write concern setting,
105+
:dbcommand:`getLastError` defaults to basic receipt acknowledgment.
109106

110107
.. _write-concern-operation:
111108
.. _write-concern-internals:
@@ -114,23 +111,24 @@ Internal Operation of Write Concern
114111
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
115112

116113
To provide write concern, :doc:`drivers </applications/drivers>` issue
117-
the :dbcommand:`getLastError` command after a write opeation and
118-
receive a document with information about the last operation. The this
114+
the :dbcommand:`getLastError` command after a write operation and
115+
receive a document with information about the last operation. This
119116
document's ``err`` field contains either:
120117

121-
- ``null``, which indicates write operations have completed
118+
- ``null``, which indicates the write operations have completed
122119
successfully, or
123120

124121
- a description of the last error encountered.
125122

126123
The definition of a "successful write" depends on the arguments
127-
specified to :dbcommand:`getLastError` or in replica sets the
128-
configuration of :data:`getLastErrorDefaults <settings.getLastErrorDefaults>`.
129-
When deciding on what level of write concern your application needs,
130-
become familiar with the :ref:`write-concern-considerations`.
124+
specified to :dbcommand:`getLastError`, or in replica sets, the
125+
configuration of :data:`getLastErrorDefaults
126+
<settings.getLastErrorDefaults>`. When deciding the level of write
127+
concern for your application, become familiar with the
128+
:ref:`write-concern-considerations`.
131129

132-
The :dbcommand:`getLastError` has the following options, that you can
133-
use to define write concern requirements.
130+
The :dbcommand:`getLastError` has the following options to configure write
131+
concern requirements.
134132

135133
- ``j`` or "journal" option
136134

@@ -145,9 +143,9 @@ use to define write concern requirements.
145143

146144
- ``w`` option
147145

148-
This option provides write concern operations for :term:`replica
149-
sets <replica set>` *and* is also used to disable write concern
150-
entirely. By default, the ``w`` option is set to ``1``, which
146+
This option provides the ability to disable write concern entirely *as
147+
well as* specifies the write concern operations for :term:`replica sets
148+
<replica set>`. By default, the ``w`` option is set to ``1``, which
151149
provides basic receipt acknowledgment on a single :program:`mongod`
152150
instance or on the :term:`primary` in a replica set.
153151

@@ -160,12 +158,13 @@ use to define write concern requirements.
160158

161159
- ``0``:
162160

163-
Disables basic acknowledgment of write operations, but does
164-
pass information about networking errors to the application.
161+
Disables basic acknowledgment of write operations, but returns
162+
information about networking errors to the application.
165163

166164
.. note:: If you disable basic operation acknowledgment write
167-
concern but enable the journal commit write concern, as
168-
in the following operation:
165+
concern but enable the journal commit write concern, the journal
166+
commit overrides the no write concern, as in the following
167+
operation:
169168

170169
.. code-block:: javascript
171170

@@ -182,29 +181,27 @@ use to define write concern requirements.
182181

183182
- *A number greater than 1*:
184183

185-
Guarantees that write write operations have propagated
186-
successfully to the specified number of replica set members
187-
including the primary. If you set ``w`` to a number that is
188-
greater than the number of set members that hold data, MongoDB
189-
waits for the non-existent members become available, which means
190-
MongoDB blocks indefinitely.
184+
Guarantees that write operations have propagated successfully to
185+
the specified number of replica set members including the primary.
186+
If you set ``w`` to a number that is greater than the number of set
187+
members that hold data, MongoDB waits for the non-existent members
188+
to become available, which means MongoDB blocks indefinitely.
191189

192190
- ``majority``:
193191

194192
Confirms that write operations have propagated to the majority of
195-
configured replica set nodes must acknowledge the write operation
193+
configured replica set; nodes must acknowledge the write operation
196194
before it succeeds. This ensures that write operation will *never*
197195
be subject to a rollback in the course of normal operation, and
198-
furthemore allows you to prevent hard coding assumptions about the
196+
furthermore allows you to prevent hard coding assumptions about the
199197
size of your replica set into your application.
200198

201199
- *A tag set*:
202200

203-
By specifying a :ref:`tag set
204-
<replica-set-configuration-tag-sets>` you can have much more fine
205-
grained control over which members of the replica set must
206-
acknowledge a write operation to satisfy the required level of
207-
write concern.
201+
By specifying a :ref:`tag set <replica-set-configuration-tag-sets>`
202+
you can have fine-grained control over which replica
203+
set members must acknowledge a write operation to satisfy the required
204+
level of write concern.
208205

209206
For more information on write concern and replica sets, see :ref:`Write
210207
Concern for Replica Sets <replica-set-write-concern>` for more information..
@@ -218,13 +215,13 @@ Bulk Inserts
218215
------------
219216

220217
In some situations you may need to insert or ingest a large amount of
221-
data into a MongoDB database. These *bulk inserts*, have some
218+
data into a MongoDB database. These *bulk inserts* have some
222219
special considerations that are different from other write
223220
operations.
224221

225222
The :method:`insert() <db.collection.insert()>` method, when passed an
226-
array of documents will perform a "bulk insert," and insert each
227-
document separately. :doc:`Drivers </applications/drivers>` each
223+
array of documents, will perform a bulk insert, and inserts each
224+
document atomically. :doc:`Drivers </applications/drivers>`
228225
provide their own interface for this kind of operation.
229226

230227
.. versionadded:: 2.2
@@ -270,10 +267,10 @@ After every insert, update, or delete operation, MongoDB must update
270267
itself. Therefore, every index on a collection adds some amount of
271268
overhead for the performance of write operations.
272269

273-
In general, the performance gains that indexes realize for *read
270+
In general, the performance gains that indexes provide for *read
274271
operations* are worth the insertion penalty; however, when optimizing
275-
write performance be careful when creating new indexes and always
276-
evaluate the indexes on the collection and ensure that your quires are
272+
write performance, be careful when creating new indexes and always
273+
evaluate the indexes on the collection and ensure that your queries are
277274
actually using these indexes.
278275

279276
For more information on indexes in MongoDB consider :doc:`/indexes`
@@ -309,37 +306,35 @@ In :term:`replica sets <replica set>`, all write operations go to the
309306
set's :term:`primary`, which applies the write operation then records
310307
the operations on the primary's operation log or :term:`oplog`. The
311308
oplog is a reproducible sequence of operations to the data
312-
set. :term:`Secondary` members of the set are always replicating the
309+
set. :term:`Secondary` members of the set are continuously replicating the
313310
oplog and applying the operations to themselves in an asynchronous
314311
process.
315312

316-
Large volumes of write operations, particularly bulk operations may
317-
create situations where secondary members have a difficult time
318-
applying replicating operations from the primary fast enough, which
313+
Large volumes of write operations, particularly bulk operations, may
314+
create situations where the secondary members have difficulty applying
315+
the replicating operations from the primary at a fast enough rate; this
319316
can cause their state to fall behind that of the primary. Secondaries
320317
that are significantly behind the primary present problems for normal
321318
operation of the replica set, particularly :ref:`failover
322319
<replica-set-failover-administration>` in the form of :ref:`rollbacks
323-
<replica-set-rollback>` as well as general
324-
:ref:`read consistency <replica-set-consistency>`.
325-
326-
To help avoid this issue, you can customize :ref:`write concern
327-
<write-operations-write-concern>` to return confirm confirmation of
328-
the write operation to another member [#write-concern-throttling]_ of
329-
the replica set ``100`` or ``1,000``) operations. This provides an
330-
opportunity for secondaries to catch up with the primary. Write
331-
concern can slow the overall progress of write operations but ensure
332-
that the secondaries can maintain a largely current state with respect
333-
to the primary.
320+
<replica-set-rollback>` as well as general :ref:`read consistency
321+
<replica-set-consistency>`.
322+
323+
To help avoid this issue, you can customize the :ref:`write concern
324+
<write-operations-write-concern>` to return confirmation of the write
325+
operation to another member [#write-concern-throttling]_ of the replica
326+
set every 100 or 1,000 operations. This provides an opportunity for
327+
secondaries to catch up with the primary. Write concern can slow the
328+
overall progress of write operations but ensure that the secondaries
329+
can maintain a largely current state with respect to the primary.
334330

335331
For more information on replica sets and write operations, see
336332
:ref:`replica-set-write-concern`, :ref:`replica-set-oplog-sizing`,
337333
:ref:`replica-set-oplog`, and :ref:`replica-set-procedure-change-oplog-size`.
338334

339-
.. [#write-concern-throttling] By calling :dbcommand:`getLastError`
340-
intermittently with a ``w`` value of ``2`` or ``majority`` to
341-
:dbcommand:`getLastError` will slow the throughput of the write
342-
operation but will prevent bulk inserts.
335+
.. [#write-concern-throttling] Calling :dbcommand:`getLastError`
336+
intermittently with a ``w`` value of ``2`` or ``majority`` will slow
337+
the throughput of the write operation but will prevent bulk inserts.
343338

344339
.. _write-operations-sharded-clusters:
345340

0 commit comments

Comments
 (0)