diff --git a/config/redirects b/config/redirects index 6fe4a9ac1c9..c97d71157ba 100644 --- a/config/redirects +++ b/config/redirects @@ -1005,8 +1005,8 @@ raw: /master/release-notes/3.3-dev-series-reference -> ${base}/master/release-no (v3.2-*]: /${version}/tutorial/migrate-config-servers-with-different-hostnames -> ${base}/${version}/tutorial/replace-config-server/ (v3.2-*]: /${version}/migrate-config-servers-with-same-hostname -> ${base}/${version}/tutorial/replace-config-server/ [v3.2]: /${version}/release-notes/3.4 -> ${base}/${version}/manual/release-notes/3.4/ -[*-v3.2]: /${version}/tutorial/perform-findAndModify-linearizable-reads -> ${base}/${version}/tutorial/perform-findAndModify-quorum-reads/ -(v3.2-*]: /${version}/tutorial/perform-findAndModify-quorum-reads -> ${base}/${version}/tutorial/perform-findAndModify-linearizable-reads/ +[v3.4-*]: /${version}/tutorial/perform-findAndModify-linearizable-reads -> ${base}/${version}/reference/read-concern/ +[*-v3.2]: /${version}/tutorial/perform-findAndModify-quorum-reads -> ${base}/${version}/reference/read-concern/ [*-v3.2]: /${version}/release-notes/3.4-downgrade -> ${base}/${version}/release-notes/ [*-v3.2]: /${version}/release-notes/3.4-downgrade-replica-set -> ${base}/${version}/release-notes/ [*-v3.2]: /${version}/release-notes/3.4-downgrade-sharded-cluster -> ${base}/${version}/release-notes/ diff --git a/source/core/crud.txt b/source/core/crud.txt index 5cf81e640b7..8392d81cf79 100644 --- a/source/core/crud.txt +++ b/source/core/crud.txt @@ -17,7 +17,6 @@ Atomicity, consistency, and distributed operations - :doc:`/core/write-operations-atomicity` - :doc:`/core/read-isolation-consistency-recency` - :doc:`/core/distributed-queries` - - :doc:`/tutorial/perform-findAndModify-linearizable-reads` Query Plan, Performance, and Analysis - :doc:`/core/query-plans` @@ -38,7 +37,6 @@ Miscellaneous /core/write-operations-atomicity /core/read-isolation-consistency-recency /core/distributed-queries - /tutorial/perform-findAndModify-linearizable-reads /core/query-plans /core/query-optimization /tutorial/analyze-query-plan diff --git a/source/includes/steps-findAndModify-quorum-reads.yaml b/source/includes/steps-findAndModify-quorum-reads.yaml deleted file mode 100644 index 9926d1ada1a..00000000000 --- a/source/includes/steps-findAndModify-quorum-reads.yaml +++ /dev/null @@ -1,55 +0,0 @@ -title: Create a unique index. -stepnum: 1 -ref: quorum-read-unique-index -pre: | - Create a unique index on the fields that will be used to specify an - exact match in the :method:`db.collection.findAndModify()` operation. - - This tutorial will use an exact match on the ``sku`` field. As such, - create a unique index on the ``sku`` field. -action: - language: javascript - code: | - db.products.createIndex( { sku: 1 }, { unique: true } ) ---- -title: Use ``findAndModify`` to read committed data. -stepnum: 2 -ref: quorum-read-findAndModify -pre: | - Use the :method:`db.collection.findAndModify()` method to make a - trivial update to the document you want to read and return the - modified document. A write concern of :writeconcern:`{ w: "majority" } - <"majority">` is required. To specify the document to read, you must - use an exact match query that is supported by a unique index. - - The following :method:`~db.collection.findAndModify()` operation - specifies an exact match on the uniquely indexed field ``sku`` and - increments the field named ``_dummy_field`` in the matching document. - While not necessary, the write concern for this command also includes - a :ref:`wc-wtimeout` value of ``5000`` milliseconds to prevent the - operation from blocking forever if the write cannot propagate to a - majority of voting members. -action: - language: javascript - code: | - var updatedDocument = db.products.findAndModify( - { - query: { sku: "abc123" }, - update: { $inc: { _dummy_field: 1 } }, - new: true, - writeConcern: { w: "majority", wtimeout: 5000 } - } - ); -post: | - Even in situations where two nodes in the replica set believe that - they are the primary, only one will be able to complete the write with - :writeconcern:`w: "majority" <"majority">`. As such, the - :method:`~db.collection.findAndModify()` method with - :writeconcern:`"majority"` write concern will be successful only when - the client has connected to the true primary to perform the operation. - - Since the quorum read procedure only increments a dummy field in the - document, you can safely repeat invocations of - :method:`~db.collection.findAndModify()`, adjusting the - :ref:`wc-wtimeout` as necessary. -... diff --git a/source/reference/command/findAndModify.txt b/source/reference/command/findAndModify.txt index 7e3e0d7bc03..0beb1d759b0 100644 --- a/source/reference/command/findAndModify.txt +++ b/source/reference/command/findAndModify.txt @@ -1028,7 +1028,3 @@ For the syntax, see :ref:`let `. update: { flavor: "orange" }, let: { targetFlavor: "cherry" } } ) - -.. seealso:: - - :ref:`perform-findAndModify-linearizable-reads` diff --git a/source/reference/method/db.collection.findAndModify.txt b/source/reference/method/db.collection.findAndModify.txt index 1be0e341a22..b0d171036e1 100644 --- a/source/reference/method/db.collection.findAndModify.txt +++ b/source/reference/method/db.collection.findAndModify.txt @@ -787,8 +787,3 @@ For the syntax, see :ref:`let `. update: { flavor: "orange" }, let: { targetFlavor: "cherry" } } ) - - -.. seealso:: - - :ref:`perform-findAndModify-linearizable-reads` diff --git a/source/tutorial/perform-findAndModify-linearizable-reads.txt b/source/tutorial/perform-findAndModify-linearizable-reads.txt deleted file mode 100644 index c4ad7c45913..00000000000 --- a/source/tutorial/perform-findAndModify-linearizable-reads.txt +++ /dev/null @@ -1,100 +0,0 @@ -.. _perform-findAndModify-linearizable-reads: - -======================================== -Linearizable Reads via ``findAndModify`` -======================================== - -.. default-domain:: mongodb - -Overview --------- - -When reading from a replica set, it is possible to read data that is -stale (i.e. may not reflect all writes that have occurred prior to the -read operation) or not durable (i.e. the state of the data may reflect -a write that has not been acknowledged by a majority or the replica set -members and thus could be rolled back), depending on the read concern -used. - -Starting in version 3.4, MongoDB introduces -:readconcern:`"linearizable"` read concern that returns durable data -that is not stale. :readconcern:`Linearizable <"linearizable">` read -concern guarantees only apply if read operations specify a query filter -that uniquely identifies a single document. - -This tutorial outlines an alternative procedure, one using -:method:`db.collection.findAndModify()` to read data that is not stale -and cannot be rolled back, for deployments using MongoDB 3.2. For -MongoDB 3.4, although the outlined procedure can be applied, see -:readconcern:`"linearizable"` read concern instead. - -Linearizable Reads via ``findAndModify`` ----------------------------------------- - -This procedure uses :method:`db.collection.findAndModify()` to read -data that is not stale and cannot be rolled back. To do so, the -procedure uses the :method:`~db.collection.findAndModify()` method with -a :ref:`write concern ` to modify a dummy field in a -document. Specifically, the procedure requires that: - -- :method:`db.collection.findAndModify()` use an **exact** match query, - and a :doc:`unique index ` **must exist** to - satisfy the query. - -- :method:`~db.collection.findAndModify()` must actually modify a - document; i.e. result in a change to the document. - -- :method:`~db.collection.findAndModify()` must use the write concern - :writeconcern:`{ w: "majority" } <"majority">`. - -.. important:: - - The "quorum read" procedure has a substantial cost over simply using - a read concern of :readconcern:`"majority"` because it incurs write - latency rather than read latency. This technique should only be used - if staleness is absolutely intolerable. - -Prerequisites -~~~~~~~~~~~~~ - -This tutorial reads from a collection named ``products``. Initialize -the collection using the following operation. - -.. code-block:: javascript - - db.products.insert( [ - { - _id: 1, - sku: "xyz123", - description: "hats", - available: [ { quantity: 25, size: "S" }, { quantity: 50, size: "M" } ], - _dummy_field: 0 - }, - { - _id: 2, - sku: "abc123", - description: "socks", - available: [ { quantity: 10, size: "L" } ], - _dummy_field: 0 - }, - { - _id: 3, - sku: "ijk123", - description: "t-shirts", - available: [ { quantity: 30, size: "M" }, { quantity: 5, size: "L" } ], - _dummy_field: 0 - } - ] ) - -The documents in this collection contain a dummy field named -``_dummy_field`` that will be incremented by the -:method:`db.collection.findAndModify()` in the tutorial. If the field -does not exist, the :method:`db.collection.findAndModify()` operation -will add the field to the document. The purpose of the field is to -ensure that the :method:`db.collection.findAndModify()` results in a -modification to the document. - -Procedure -~~~~~~~~~ - -.. include:: /includes/steps/findAndModify-quorum-reads.rst