Definition定义
Mongo.setCausalConsistency(<boolean>)Enables or disables causal consistency on the connection object. Causal consistency is disabled on the connection object by default.启用或禁用连接对象上的因果一致性。默认情况下,连接对象上禁用因果一致性。Note
TheMongo()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:该方法还可以接受布尔参数:trueto enable causal consistency:为了实现因果一致性:conn.setCausalConsistency(true);falseto disable causal consistency:禁用因果一致性:conn.setCausalConsistency(false);
Compatibility兼容性
This method is available in deployments hosted in the following environments:此方法在以下环境中托管的部署中可用:
- MongoDB Atlas
: The fully managed service for MongoDB deployments in the cloud:云中MongoDB部署的完全托管服务
- MongoDB Enterprise
: The subscription-based, self-managed version of MongoDB:MongoDB的基于订阅的自我管理版本 - MongoDB Community
: The source-available, free-to-use, and self-managed version of MongoDB:MongoDB的源代码可用、免费使用和自我管理版本
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();