Database Manual / Reference / Database Commands / Sharding

removeShardFromZone (database command数据库命令)

Definition定义

removeShardFromZone

The removeShardFromZone administrative command removes the association between a shard and a zone.removeShardFromZone管理命令删除分片和区域之间的关联。

Tip

In mongosh, this command can also be run through the sh.removeShardFromZone() helper method.mongosh中,此命令也可以通过sh.removeShardFromZone()辅助方法运行。

Helper methods are convenient for mongosh users, but they may not return the same level of information as database commands. 助手方法对mongosh用户来说很方便,但它们可能不会返回与数据库命令相同级别的信息。In cases where the convenience is not needed or the additional return fields are required, use the database command.如果不需要便利性或需要额外的返回字段,请使用database命令。

Compatibility兼容性

This command 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的源代码可用、免费使用和自我管理版本

Syntax语法

You can only run removeShardFromZone on the admin database from a mongos instance.您只能从mongos实例在admin数据库上运行removeShardFromZone

The command has the following syntax:该命令具有以下语法:

db.adminCommand(
{
removeShardFromZone: <string>,
zone: <string>
}
)

Command Fields命令字段

The command takes the following fields:该命令包含以下字段:

Field字段Type类型Description描述
removeShardFromZonestring字符串

The name of the shard from which to remove the zone association.要从中删除区域关联的分片的名称。

zonestring字符串

The name of the zone whose association with the shard you want to remove.与要删除的分片关联的区域的名称。

mongosh provides the helper method sh.removeShardFromZone().提供了辅助方法sh.removeShardFromZone()

Behavior行为

removeShardFromZone does not remove ranges associated with the zone.不会删除与该区域关联的范围。

To completely remove a zone from the cluster, you must run removeShardFromZone on each shard associated with the zone.要从集群中完全删除一个区域,您必须在与该区域关联的每个分片上运行removeShardFromZone

If the shard specified is the last shard associated with the zone, you must ensure there are no remaining shard key ranges associated with the zone. 如果指定的分片是与该区域关联的最后一个分片,则必须确保没有剩余的与该区域相关的分片键范围。Use updateZoneKeyRange to remove any existing ranges associated with the zone before running removeShardFromZone.在运行updateZoneKeyRange之前,使用removeShardFromZone删除与该区域关联的任何现有范围。

See the zone manual page for more information on zones in sharded clusters.有关分片集群中区域的更多信息,请参阅区域手册页面。

Security安全

For sharded clusters that enforce access control, you must authenticate either as:对于实施访问控制的分片集群,您必须通过以下方式之一进行身份验证:

  • a user whose privileges include:其权限包括:

    • update on the shards collection in the config database, andupdate更新config数据库中的shards集合,以及
    • find on the tags collection in the config database;config数据库的tags集合中find查找;

    or, alternatively或者,作为另一种选择

  • a user whose privileges include enableSharding on the cluster resource.其权限包括在集群资源上enableSharding(启用分片)的用户。

The clusterAdmin or clusterManager built-in roles have the appropriate permissions for issuing removeShardFromZone. clusterAdminclusterManager内置角色具有发布removeShardFromZone的适当权限。See the Role-Based Access Control manual page for more information.有关更多信息,请参阅removeShardFromZone基于角色的访问控制手册页。

Example示例

The following example removes the association between shard0000 and zone NYC:以下示例删除了shard0000和区域NYC之间的关联:

db.adminCommand( { removeShardFromZone : "shard0000" , zone : "NYC" } )