Docs Menu
Docs Home
/
MongoDB Manual
/ / /

Mongo.setCausalConsistency()

On this page

  • Definition
  • Compatibility
  • Example
Mongo.setCausalConsistency(<boolean>)

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

Note

The Mongo() connection object may have causal consistency disabled even though sessions may have causal consistency enabled or vice versa. See Mongo.startSession().

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

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

The method also can accept a boolean argument:

  • true to enable causal consistency:

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

    conn.setCausalConsistency(false);

This method is available in deployments hosted in the following environments:

  • MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud

The following mongosh operation enables causal consistency on the Mongo() connection object associated with mongosh's global db variable:

db.getMongo().setCausalConsistency();

Tip

See also:

Back

Mongo.getWriteConcern