Docs Menu
Docs Home
/
Database Manual
/ / /

db.collection.getShardLocation() (mongosh method)

db.collection.getShardLocation()

New in version 8.1.

Returns a document containing the shards where the collection is located and whether the collection is sharded.

Important

mongosh Method

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

The getShardLocation() method is a wrapper for the $listClusterCatalog aggregation stage.

The getShardLocation() method returns a document with the following fields:

Field
Type
Description

shards

Array

Shards where the collection's data resides.

sharded

Boolean

Indicates whether the collection is sharded.

If you run the method on an unsharded deployment:

  • The shards array is empty.

  • The sharded field is false.

This method is available in deployments hosted in the following environments:

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

Important

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

db.<collection>.getShardLocation()

The following example shows the shards that contain the data in the sample_mflix.movies collection:

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

If you run the command on a sharded cluster but the collection is not sharded, the sharded field is false and the shards array only contains the config shard:

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

If you run the command on an unsharded deployment, the sharded field is false and the shards array is empty:

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

Back

db.collection.checkMetadataConsistency

On this page