On this page本页内容
Mongo.setCausalConsistency(<boolean>)
Enables or disables causal consistency on the connection object. 启用或禁用连接对象上的因果一致性。Causal consistency is disabled on the connection object by default.默认情况下,在连接对象上禁用因果一致性。
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);
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();