Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 44 lines (33 sloc) 1.881 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
====================================
Replica Set Read and Write Semantics
====================================

.. default-domain:: mongodb

From the perspective of a client application, whether a MongoDB
instance is running as a single server (i.e. "standalone") or a
:term:`replica set` is transparent.

By default, in MongoDB, read operations to a replica set return results
from the :doc:`primary </core/replica-set-primary>` and are
:term:`consistent <strict consistency>` with the last write operation.

Users may configure :term:`read preference` on a per-connection basis
to prefer that the read operations return on the :term:`secondary`
members. If clients configure the :term:`read preference` to permit
secondary reads, read operations cannot return from :term:`secondary`
members that have not replicated more recent updates or
operations. When reading from a secondary, a query may return data that
reflects a previous state.

This behavior is sometimes characterized as :term:`eventual
consistency` because the secondary member's state will *eventually*
reflect the primary's state and MongoDB cannot guarantee :term:`strict
consistency` for read operations from secondary members.

To guarantee consistency for reads from secondary members, you can
configure the :term:`client` and :term:`driver` to ensure that write
operations succeed on all members before completing successfully. See
:doc:`/core/write-concern` for more information. Additionally, such
configuration can help prevent :doc:`/core/replica-set-rollbacks`
during a failover.

.. note::

   :term:`Sharded clusters <sharded cluster>` where the shards are also
   replica sets provide the same operational semantics with
   regards to write and read operations.

.. include:: /includes/toc/dfn-list-replica-set-read-write-semantics.rst

.. include:: /includes/toc/replica-set-read-write-semantics.rst
Something went wrong with that request. Please try again.