Menu Docs

configureCollectionBalancing

configureCollectionBalancing

Novidades na versão 5.3.

Configures balancer settings for a sharded collection, such as setting the chunk size for and defragmenting the collection.

Esse comando está disponível em implantações hospedadas nos seguintes ambientes:

  • MongoDB Atlas: o serviço totalmente gerenciado para implantações do MongoDB na nuvem

Observação

Este comando é aceito em todos os clusters do MongoDB Atlas. Para obter informações sobre o suporte do Atlas a todos os comandos, consulte Comandos não suportados.

  • MongoDB Enterprise: a versão autogerenciada e baseada em assinatura do MongoDB

  • MongoDB Community: uma versão com código disponível, de uso gratuito e autogerenciada do MongoDB

O comando tem a seguinte sintaxe:

db.adminCommand(
{
configureCollectionBalancing: "<db>.<collection>",
chunkSize: <num>,
defragmentCollection: <bool>
enableAutoMerger: <bool>
}
)

configureCollectionBalancing tem os seguintes campos:

Campo
Tipo
necessidade
Descrição

configureCollectionBalancing

string

Obrigatório

The name of the database and sharded collection to configure.

chunkSize

inteiro

Opcional

Sets the chunk size in MiB for the collection. The recommended size is 256, 512, or larger. For details on default behavior, see Default Behavior When chunkSize Is Not Specified.

defragmentCollection

booleano

Opcional

Causes the balancer to defragment the collection. Defaults to false.

enableAutoMerger

booleano

Opcional

Whether or not the AutoMerger takes this collection into account. Defaults to true.

For more information, see Partição de dados com blocos.

To configure the chunk defragmentation throttling time parameter, see chunkDefragmentationThrottlingMS.

To learn about defragmenting sharded collections, see Coleções fragmentadas de desfragmento.

If you do not specify chunkSize for a collection and no custom size has been set previously, the global default chunkSize is used for balancing.

If you use configureCollectionBalancing with chunkSize: 0, the per-collection chunkSize is reset and the global default chunkSize is used for balancing.

For more information on configuring default chunkSize, see Modify Range Size in a Sharded Cluster.

If you do not specify enableAutoMerger for a collection and no custom automerging behavior has been previously set, it defaults to true and will be taken into account by the AutoMerger.

To change the chunk size for a sharded collection, use the chunkSize option:

db.adminCommand( {
configureCollectionBalancing: "test.students",
chunkSize: 256
} )

Use this command to change the chunk size for the given collection.

Aviso

By default, MongoDB cannot move a chunk if the number of documents in the chunk is greater than 2 times the result of dividing the configured chunk size by the average document size.

To find the average document size, see the avgObjSize field in the output of the db.collection.stats() method.

For more information, see Tamanho do Intervalo.

Aviso

We do not recommend using defragmentCollection to defragment sharded collections for MongoDB 6.0.0 to 6.0.3 and MongoDB 6.1.0 to 6.1.1, as the defragmentation process on these releases can make databases and collections unavailable for extended periods of time.

To tell the balancer to defragment a sharded collection, use the defragmentCollection option:

db.adminCommand( {
configureCollectionBalancing: "test.students",
defragmentCollection: true
} )

Use this command to have the balancer defragment a sharded collection. To monitor the chunk defragmentation process, use the balancerCollectionStatus command.

To learn more about defragmenting sharded collections, see Coleções fragmentadas de desfragmento.

To defragment a sharded collection while updating the chunk size, use the defragmentCollection option and the chunkSize option together:

db.adminCommand( {
configureCollectionBalancing: "test.students",
chunkSize: 512,
defragmentCollection: true
} )

To explicitly disable the AutoMerger on a collection, set the enableAutoMerger option to false:

db.adminCommand( {
configureCollectionBalancing: "test.students",
enableAutoMerger: false
} )