Docs HomeMongoDB Manual

Mongo.setCausalConsistency()

On this page本页内容

Definition定义

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. Mongo()连接对象可能已禁用因果一致性,即使会话可能已启用因果一致性(反之亦然)。See Mongo.startSession().请参见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);

Example实例

The following mongosh operation enables causal consistency on the Mongo() connection object associated with mongosh's global db variable:以下mongosh操作在与mongosh的全局db变量关联的Mongo()连接对象上启用因果一致性:

db.getMongo().setCausalConsistency();
Tip

See also: 另请参阅: