@@ -21,20 +21,18 @@ Write Concern
21
21
22
22
When a :term:`client` sends a write operation to a database server,
23
23
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
25
26
: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
28
28
configure :dbcommand:`getLastError` to return only after the write
29
29
operation has propagated to more than one member of the set or to a
30
30
majority of the set's members.
31
31
32
- Many drivers have a "safe" or "write concern" mode that automatically
32
+ Many drivers have a "safe" mode or "write concern" that automatically
33
33
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.
38
36
39
37
However, safe writes can take longer to return and are not required in
40
38
all applications. Using the ``w: "majority"`` option for
@@ -47,37 +45,37 @@ of the replica set members:
47
45
.. code-block:: javascript
48
46
49
47
db.runCommand( { getLastError: 1, w: "majority" } )
50
- db.getLastError ("majority")
48
+ db.getLastErrorObj ("majority")
51
49
52
50
You may also specify ``w: 2`` so that the write operation replicates
53
51
to a second member before the command returns.
54
52
55
53
.. note::
56
54
57
- :dbcommand:`getLastError` assumes the current host ,
55
+ :dbcommand:`getLastError` assumes the primary replica node ,
58
56
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.
61
60
62
61
You can also configure a "default" :dbcommand:`getLastError` behavior on the
63
62
replica set configuration. For instance:
64
63
65
64
.. code-block:: javascript
66
65
67
66
cfg = rs.conf()
68
- cfg.settings.getLastErrorDefaults = {w: "majority", fsync: false, j: true}
67
+ cfg.settings.getLastErrorDefaults = {w: "majority", j: true}
69
68
rs.reconfig(cfg)
70
69
71
70
When the new configuration is active, the effect of the
72
71
: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.
81
79
82
80
.. index:: read preference
83
81
.. index:: slaveOk
0 commit comments