Skip to content

Commit e24de7a

Browse files
author
Dave
authored
DOCSP-16266 get set write concern v6.0 (#1041)
* DOCSP-16266 get set writeConcern * Staging fixes * Review Feedback * Review Feedback * Update release notes
1 parent 3a3268e commit e24de7a

File tree

6 files changed

+198
-3
lines changed

6 files changed

+198
-3
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
=======================
2+
Mongo.getWriteConcern()
3+
=======================
4+
5+
.. default-domain:: mongodb
6+
7+
.. contents:: On this page
8+
:local:
9+
:backlinks: none
10+
:depth: 1
11+
:class: singlecol
12+
13+
Definition
14+
----------
15+
16+
.. method:: Mongo.getWriteConcern()
17+
18+
:returns: The current :term:`write concern` for the :method:`Mongo()
19+
<db.getMongo()>` connection object.
20+
21+
See the :ref:`write-concern` for an introduction to write concerns
22+
in MongoDB.
23+
24+
Syntax
25+
------
26+
27+
The command takes the following form:
28+
29+
.. code-block:: javascript
30+
31+
db.getMongo().getWriteConcern()
32+
33+
This operation returns a document with the following values:
34+
35+
.. code-block:: javascript
36+
:copyable: false
37+
38+
{ w: <value>, wtimeout: <number>, j: <boolean> }
39+
40+
The fields are:
41+
42+
.. list-table::
43+
:header-rows: 1
44+
45+
* - Field
46+
- Description
47+
48+
* - ``w``
49+
- The number of :binary:`~bin.mongod` or :binary:`~bin.mongod`
50+
instances that must acknowledge a write. Possible values are:
51+
52+
- "majority". A majority of the target instances must
53+
acknowledge the write.
54+
- <number>. The specified number of target instances must
55+
acknowledge the write.
56+
- <custom write concern name>. A user defined write concern, the
57+
tagged instances must acknowledge the write.
58+
59+
See :ref:`write concern specification <wc-w>` for details.
60+
61+
* - ``j``
62+
- A boolean value. ``j: true`` requests acknowledgment that the
63+
write operation has been written to the :ref:`on-disk journal
64+
<journaling-internals>`.
65+
66+
* - ``wtimeout``
67+
- The number of milliseconds to wait for acknowledgement of the
68+
write concern. ``wtimeout`` is only applicable when ``w`` has a
69+
value greater than ``1``.
70+
71+
Example
72+
-------
73+
74+
To return the current write concern, enter the following:
75+
76+
.. code-block:: javascript
77+
78+
db.getMongo().getWriteConcern()
79+
80+
When a write concern is specified using
81+
:method:`Mongo.setWriteConcern()`, the output of
82+
``Mongo.getWriteConcern()`` is similar to:
83+
84+
.. code-block:: javascript
85+
86+
WriteConcern { w: 2, wtimeout: 1000, j: true }
87+
88+
The ``Mongo.getWriteConcern()`` command returns an empty line if no
89+
write concern has been specified.
90+
91+
.. seealso::
92+
93+
- :method:`~Mongo.setWriteConcern()`
94+
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
=======================
2+
Mongo.setWriteConcern()
3+
=======================
4+
5+
.. default-domain:: mongodb
6+
7+
.. contents:: On this page
8+
:local:
9+
:backlinks: none
10+
:depth: 1
11+
:class: singlecol
12+
13+
Definition
14+
----------
15+
16+
.. method:: Mongo.setWriteConcern()
17+
18+
Sets the :term:`write concern` for the :method:`Mongo()
19+
<db.getMongo()>` connection object.
20+
21+
See the :ref:`write-concern` for an introduction to write concerns
22+
in MongoDB.
23+
24+
Syntax
25+
------
26+
27+
The command takes the following form:
28+
29+
.. code-block:: javascript
30+
31+
db.getMongo().setWriteConcern( { w: <value>, j: <boolean>, wtimeout: <number> } )
32+
33+
The fields are:
34+
35+
.. list-table::
36+
:header-rows: 1
37+
38+
* - Field
39+
- Description
40+
41+
* - ``w``
42+
- The number of :binary:`~bin.mongod` or :binary:`~bin.mongod`
43+
instances that must acknowledge a write. Possible values are:
44+
45+
- "majority". A majority of the target instances must
46+
acknowledge the write.
47+
- <number>. The specified number of target instances must
48+
acknowledge the write.
49+
- <custom write concern name>. A user defined write concern, the
50+
tagged instances must acknowledge the write.
51+
52+
See :ref:`write concern specification <wc-w>` for details.
53+
54+
* - ``j``
55+
- A boolean value. ``j: true`` requests acknowledgment that the
56+
write operation has been written to the :ref:`on-disk journal
57+
<journaling-internals>`.
58+
59+
* - ``wtimeout``
60+
- The number of milliseconds to wait for acknowledgement of the
61+
write concern. ``wtimeout`` is only applicable when ``w`` has a
62+
value greater than ``1``.
63+
64+
Example
65+
-------
66+
67+
In the following example:
68+
69+
- Two :binary:`~bin.mongod` or :binary:`~bin.mongod` instances must
70+
acknowledge writes.
71+
- There is a ``1`` second timeout to wait for write acknowledgements.
72+
73+
.. code-block:: javascript
74+
75+
db.getMongo().setWriteConcern( { w: 2, wtimeout: 1000 } )
76+
77+
.. seealso::
78+
79+
- :method:`~Mongo.getWriteConcern()`
80+

source/reference/method/js-connection.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,18 @@ Connection Methods
4040
* - :method:`Mongo.getReadPrefTagSet()`
4141
- Returns the read preference tag set for the MongoDB connection.
4242

43+
* - :method:`Mongo.getWriteConcern`
44+
- Returns the :term:`write concern` for the connection object.
45+
4346
* - :method:`Mongo.setCausalConsistency()`
4447
- Enables or disables causal consistency on the connection object.
4548

4649
* - :method:`Mongo.setReadPref()`
4750
- Sets the :term:`read preference` for the MongoDB connection.
4851

52+
* - :method:`Mongo.setWriteConcern`
53+
- Sets the :term:`write concern` for the connection object.
54+
4955
* - :method:`Mongo.startSession()`
5056
- Starts a session on the connection object.
5157

@@ -72,9 +78,11 @@ Connection Methods
7278
/reference/method/Mongo.getDBs
7379
/reference/method/Mongo.getReadPrefMode
7480
/reference/method/Mongo.getReadPrefTagSet
81+
/reference/method/Mongo.getWriteConcern
7582
/reference/method/Mongo.setCausalConsistency
7683
/reference/method/Mongo.setReadPref
7784
/reference/method/Mongo.startSession
85+
/reference/method/Mongo.setWriteConcern
7886
/reference/method/Mongo.watch
7987
/reference/method/Session
8088
/reference/method/SessionOptions

source/reference/write-concern.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ available:
112112

113113
See :ref:`wc-ack-behavior` for when :binary:`~bin.mongod` instances
114114
acknowledge the write.
115-
115+
116+
.. _write-concern-lv-number:
117+
116118
* - .. writeconcern:: <number>
117119

118120
- Requests acknowledgment that the write operation has propagated
@@ -188,8 +190,8 @@ available:
188190
~~~~~~~~~~~~
189191

190192
The ``j`` option requests acknowledgment from MongoDB that
191-
the write operation has been written to the :doc:`on-disk journal
192-
</core/journaling>`.
193+
the write operation has been written to the :ref:`on-disk journal
194+
<journaling-internals>`.
193195

194196
.. list-table::
195197
:widths: 20 80

source/release-notes/6.0.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ Starting in MongoDB 6.0, you can use :ref:`change streams
9696
after changes (the document pre- and post-images). For examples, see
9797
:ref:`db.collection.watch-change-streams-pre-and-post-images-example`.
9898

99+
Connections
100+
~~~~~~~~~~~
101+
102+
Starting in MongoDB 6.0, the :method:`Mongo() <db.getMongo()>`
103+
connection object has the following new methods:
104+
105+
- :method:`Mongo.getWriteConcern()` returns the :term:`write concern`
106+
- :method:`Mongo.setWriteConcern()` sets the :term:`write concern`
107+
99108
.. _6.0-upgrade:
100109

101110
Upgrade Procedures

source/tutorial/manage-journaling.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _manage-journaling:
2+
13
=================
24
Manage Journaling
35
=================

0 commit comments

Comments
 (0)