Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

44 lines (33 sloc) 1.878 kb
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 can 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
Jump to Line
Something went wrong with that request. Please try again.