문서 메뉴

문서 홈애플리케이션 개발MongoDB 매뉴얼

$shardedDataDistribution (aggregation)

이 페이지의 내용

  • 정의
  • 구문
  • 출력 필드
  • 예제
  • 모든 샤드 데이터 분산 메트릭 반환
  • 특정 샤드에 대한 지표 반환
  • 네임스페이스에 대한 지표 반환
  • 고아 문서가 남아 있지 않은지 확인
$shardedDataDistribution

버전 6.0.3에 추가되었습니다.

샤드 컬렉션의 데이터 분포에 대한 정보를 반환합니다.

참고

이 애그리게이션 단계는 mongos 에서만 사용할 수 있습니다.

이 애그리게이션 단계는 admin 데이터베이스에서 실행해야 합니다. 사용자에게 shardedDataDistribution 권한 작업이 있어야 합니다.

shardedDataDistribution 단계에는 다음과 같은 구문이 있습니다.

db.aggregate( [
{ $shardedDataDistribution: { } }
] )

$shardedDataDistribution 단계는 데이터베이스의 각 샤드 collection에 대한 문서 배열을 출력합니다. 이러한 문서에는 다음 필드가 포함되어 있습니다.

필드 이름
데이터 유형
설명
ns
문자열
샤드 컬렉션의 네임스페이스입니다.
shards
배열
각 샤드에 대한 데이터 배포 정보가 포함된 컬렉션의 샤드입니다.
shards.numOrphanedDocs
integer
샤드에 있는 고아 문서의 수입니다.
shards.numOwnedDocuments
integer
샤드가 소유한 문서 수입니다.
shards.ownedSizeBytes
integer
샤드가 소유한 문서의 저장 공간(바이트)입니다.
shards.orphanedSizeBytes
integer
샤드에 있는 고아 문서의 저장 공간(바이트)입니다.

모든 샤드 데이터 분포 지표를 반환하려면 다음을 실행합니다.

db.aggregate([
{ $shardedDataDistribution: { } }
])

출력 예시:

[
{
"ns": "test.names",
"shards": [
{
"shardName": "shard-1",
"numOrphanedDocs": 0,
"numOwnedDocuments": 6,
"ownedSizeBytes": 366,
"orphanedSizeBytes": 0
},
{
"shardName": "shard-2",
"numOrphanedDocs": 0,
"numOwnedDocuments": 6,
"ownedSizeBytes": 366,
"orphanedSizeBytes": 0
}
]
}
]

특정 샤드에 대한 샤드 데이터 분포 지표를 반환하려면 다음을 실행합니다.

db.aggregate([
{ $shardedDataDistribution: { } },
{ $match: { "shards.shardName": "<name of the shard>" } }
])

네임스페이스에 대한 샤드 데이터 배포 데이터를 반환하려면 다음을 실행합니다.

db.aggregate([
{ $shardedDataDistribution: { } },
{ $match: { "ns": "<database>.<collection>" } }
])

MongoDB 6 부터 시작.0.3 $shardedDataDistribution 단계를 사용하여 애그리게이션을 실행하여 고아 문서가 남아 있지 않은지 확인할 수 있습니다.

db.aggregate([
{ $shardedDataDistribution: { } },
{ $match: { "ns": "<database>.<collection>" } }
])

$shardedDataDistribution 다음과 유사한 출력이 있습니다.

[
{
"ns": "test.names",
"shards": [
{
"shardName": "shard-1",
"numOrphanedDocs": 0,
"numOwnedDocuments": 6,
"ownedSizeBytes": 366,
"orphanedSizeBytes": 0
},
{
"shardName": "shard-2",
"numOrphanedDocs": 0,
"numOwnedDocuments": 6,
"ownedSizeBytes": 366,
"orphanedSizeBytes": 0
}
]
}
]

클러스터의 각 샤드에 대해 "numOrphanedDocs"0 인지 확인합니다.

← $setWindowFields (aggregation)