setUserWriteBlockMode
定义
setUserWriteBlockMode
6.0 版本中的新功能。
The
setUserWriteBlockMode
command blocks and unblocks writes to the entire cluster.During cluster-to-cluster sync,
mongosync
, the cluster-to-cluster synchronization tool, uses thesetUserWriteBlockMode
command to block writes on the destination cluster. For more information, see the HTTP API start command.注意
Users and applications with the
bypassWriteBlockingMode
privilege can bypass the block and continue to perform writes.
兼容性
此命令可用于以下环境中托管的部署:
MongoDB Enterprise:基于订阅、自我管理的 MongoDB 版本
MongoDB Community:源代码可用、免费使用且可自行管理的 MongoDB 版本
重要
MongoDB Atlas集群不支持此命令。 有关Atlas支持所有命令的信息,请参阅不支持的命令。
语法
该命令具有以下语法:
db.adminCommand( { setUserWriteBlockMode: 1, global: <boolean> } )
命令字段
该命令接受以下字段:
字段 | 类型 | 说明 |
---|---|---|
| 整型 | Set this field to |
| 布尔 | Blocks writes on a cluster when set to |
必需的访问权限
To execute the setUserWriteBlockMode
command, the user must
have the setUserWriteBlockMode
privilege.
例子
Enable user write block mode:
db.adminCommand( { setUserWriteBlockMode: 1, global: true } ) Add a record to the collection:
db.names.insertOne( { name: "George Washington Cable" } ) The server blocks the write because the user write block is enabled.
Example Output:
MongoServerError: User writes blocked Disable user write block mode:
db.adminCommand( { setUserWriteBlockMode: 1, global: false } ) Add a record to the collection:
db.names.insertOne( { name: "George Washington Cable" } ) The
insertOne()
method writes to a collection. The server allows the write because the user write block is disabled.