Skip to content

Commit 37f12ff

Browse files
cleanup, success is not what getLastError returns, for foilures and reporting what occurred like after an update
1 parent fe99bd7 commit 37f12ff

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

source/applications/replication.txt

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,18 @@ Write Concern
2121

2222
When a :term:`client` sends a write operation to a database server,
2323
the operation will return without waiting for the operation to succeed
24-
or return. To verify that the operation is successful, use the
24+
or complete. To verify that the operation has completed,
25+
and to check for an error, use the
2526
:dbcommand:`getLastError` command. You can configure
26-
:dbcommand:`getLastError` to return after journal flushes to disk or
27-
after the data itself flushes to disk. For replica sets, you can
27+
:dbcommand:`getLastError` to wait until the journal flushes to disk or the data itself flushes to disk. For replica sets, you can
2828
configure :dbcommand:`getLastError` to return only after the write
2929
operation has propagated to more than one member of the set or to a
3030
majority of the set's members.
3131

32-
Many drivers have a "safe" or "write concern" mode that automatically
32+
Many drivers have a "safe" mode or "write concern" that automatically
3333
issues a :dbcommand:`getLastError` command following write
34-
operations to ensure that they succeed. "Safe mode,"
35-
provides confirmation of write operations to clients, which is often
36-
the expected method of operation, and is particularly useful when
37-
using standalone instances.
34+
operations to ensure that they complete. "Safe mode,"
35+
provides confirmation of write operations to the client.
3836

3937
However, safe writes can take longer to return and are not required in
4038
all applications. Using the ``w: "majority"`` option for
@@ -47,37 +45,37 @@ of the replica set members:
4745
.. code-block:: javascript
4846

4947
db.runCommand( { getLastError: 1, w: "majority" } )
50-
db.getLastError("majority")
48+
db.getLastErrorObj("majority")
5149

5250
You may also specify ``w: 2`` so that the write operation replicates
5351
to a second member before the command returns.
5452

5553
.. note::
5654

57-
:dbcommand:`getLastError` assumes the current host,
55+
:dbcommand:`getLastError` assumes the primary replica node,
5856
therefore, ``w: 2`` waits until the :term:`primary` and one other
59-
member of the replica set commits the write operation. The current
60-
primary always counts as ``w: 1``.
57+
member of the replica set acknowledges the write operation. The current
58+
primary always counts as ``w: 1``. Using ``w: 0`` makes no sense and should
59+
not be done.
6160

6261
You can also configure a "default" :dbcommand:`getLastError` behavior on the
6362
replica set configuration. For instance:
6463

6564
.. code-block:: javascript
6665

6766
cfg = rs.conf()
68-
cfg.settings.getLastErrorDefaults = {w: "majority", fsync: false, j: true}
67+
cfg.settings.getLastErrorDefaults = {w: "majority", j: true}
6968
rs.reconfig(cfg)
7069

7170
When the new configuration is active, the effect of the
7271
:dbcommand:`getLastError` operation will wait until the write
73-
operation has succeeded on a majority of the set members before writing. By
74-
specifying ``fsync: false`` and ``j: true`` a successful commit of
75-
the operation to the journal is all that :dbcommand:`getLastError`
76-
requires to return succesullly, rather than a full flush to disk. Use this the
77-
:data:`getLastErrorDefaults`" setting on the sever level to define the
78-
standards for a set-wide "safe mode." The default setting will only
79-
affect :dbcommand:`getLastError` commands with *no* other
80-
arguments.
72+
operation has completed on a majority of the set members before writing. By
73+
specifying ``j: true`` a complete commit of the operations to the
74+
journal is all that :dbcommand:`getLastError` requires to return. Use the
75+
:data:`getLastErrorDefaults`" setting in the :ref:`replica set` configuration
76+
to define the standards for a set-wide "safe mode."
77+
The default setting will only affect :dbcommand:`getLastError`
78+
commands with *no* other arguments.
8179

8280
.. index:: read preference
8381
.. index:: slaveOk

0 commit comments

Comments
 (0)