configureCollectionBalancing
정의
호환성
이 명령은 다음 환경에서 호스팅되는 배포에서 사용할 수 있습니다.
MongoDB Atlas: 클라우드에서의 MongoDB 배포를 위한 완전 관리형 서비스
참고
이 명령은 모든 MongoDB Atlas 클러스터에서 지원됩니다. 모든 명령에 대한 Atlas 지원에 관해 자세히 알아보려면 지원되지 않는 명령을 참조하십시오.
MongoDB Enterprise: MongoDB의 구독 기반 자체 관리 버전
MongoDB Community: MongoDB의 소스 사용 가능 무료 자체 관리 버전
구문
명령은 다음과 같은 구문을 가집니다:
db.adminCommand( { configureCollectionBalancing: "<db>.<collection>", chunkSize: <num>, defragmentCollection: <bool> enableAutoMerger: <bool> } )
명령 필드
configureCollectionBalancing
에는 다음과 같은 필드가 있습니다.
필드 | 유형 | 필요성 | 설명 |
---|---|---|---|
| 문자열 | 필수 사항 | The name of the database and sharded collection to configure. |
| integer | 옵션 | 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. |
| 부울 | 옵션 | Causes the balancer to defragment the collection.
Defaults to |
| 부울 | 옵션 | Whether or not the AutoMerger takes this collection into account.
Defaults to |
For more information, see Data Partitioning with Chunks.
To configure the chunk defragmentation throttling time parameter, see
chunkDefragmentationThrottlingMS
.
To learn about defragmenting sharded collections, see 조각난 컬렉션 조각 모음.
행동
Default Behavior When chunkSize Is Not Specified
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.
Specifying chunkSize: 0
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.
Default Behavior When enableAutoMerger Is Not Specified
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.
예시
Configure Chunk Size
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.
경고
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 Range Size.
Defragment Collections
경고
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 조각난 컬렉션 조각 모음.
Reconfigure and Defragment Collections
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 } )
Disable the AutoMerger on a Collection
To explicitly disable the AutoMerger on a collection,
set the enableAutoMerger
option to false
:
db.adminCommand( { configureCollectionBalancing: "test.students", enableAutoMerger: false } )