对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

db. 集合.getShardLocation()(mongosh方法)

db.collection.getShardLocation()

8.1版本新增。

返回包含集合所在分片的文档,以及集合是否分片。

重要

mongosh 方法

This page documents a mongosh method. This is not the documentation for database commands or language-specific drivers.

getShardLocation() 方法是 $listClusterCatalog 聚合阶段的包装器。

getShardLocation() 方法返回包含以下字段的文档:

字段
类型
说明

shards

阵列

集合数据所在的分片。

sharded

布尔

指示集合是否分片的。

如果在未分片部署上运行该方法:

  • shards数组为空。

  • sharded字段为 false。

此方法可用于以下环境中托管的部署:

  • MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud

重要

This command is not supported in M0 and Flex clusters. For more information, see Unsupported Commands.

db.<collection>.getShardLocation()

以下示例显示了包含 sample_mflix.movies集合中的数据的分片:

use sample_mflix
db.movies.getShardLocation()
{ shards: [ 'shard01', 'shard02' ], sharded: true }

如果您在分片集群上运行该命令,但集合未分片的,则 sharded字段为 false,且 shards数组仅包含 config分片:

use sample_mflix
db.movies.getShardLocation()
{ shards: [ 'config' ], sharded: false }

如果在未分片部署上运行该命令,则 sharded字段为 false,shards数组为空:

use sample_mflix
db.movies.getShardLocation()
{ shards: [], sharded: false }
给本页内容打分