Mongo.setCausalConsistency()

Definition

  • Mongo.setCausalConsistency()

New in version 3.6.

Enables or disables causal consistencyon the connection object. Causal consistency is disabled on theconnection object by default.

Note

The Mongo connection object may have causal consistencydisabled even though sessions may have causal consistency enabledor vice versa. See Mongo.startSession().

To enable causal consistency for the connection object, call themethod without any argument:

  1. var conn = Mongo("localhost:27017");
  2. conn.setCausalConsistency();

The method also can accept a boolean argument:

  • true to enable causal consistency:
  1. conn.setCausalConsistency(true);
  • false to disable causal consistency:
  1. conn.setCausalConsistency(false);

Example

The following mongo shell operation enables causalconsistency on the Mongo connection object associated withthe mongo shell’s global db variable:

  1. db.getMongo().setCausalConsistency();

To check if causal consistency is enabled for a connection, use theMongo.isCausalConsistency() method. For example:

  1. db.getMongo().isCausalConsistency();

See also