AI エージェント向け: ドキュメントインデックスは https://www.mongodb.com/ja-jp/docs/llms.txt で利用できます。すべてのページの markdown バージョンは、いずれかの URL パスに .md を追加することで利用できます。
Docs Menu

mergeChunks(データベースコマンド)

mergeChunks

For a sharded collection, mergeChunks combines contiguous chunk ranges on a shard into a single chunk. Issue the mergeChunks command on the admin database from a mongos instance.

このコマンドは、次の環境でホストされている配置で使用できます。

  • MongoDB Atlas はクラウドでの MongoDB 配置のための完全管理サービスです
  • MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン

  • MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン

このコマンドの構文は、次のとおりです。

db.adminCommand(
{
mergeChunks: <namespace>,
bounds : [
{ <shardKeyField>: <minFieldValue> },
{ <shardKeyField>: <maxFieldValue> }
]
}
)

For compound shard keys, you must include the full shard key in the bounds specification. For example, if the shard key is { x: 1, y: 1 }, mergeChunks has the following form:

db.adminCommand(
{
mergeChunks: <namespace>,
bounds: [
{ x: <minValue>, y: <minValue> },
{ x: <maxValue>, y: <maxValue> }
]
}
)

このコマンドは、次のフィールドを使用します。

フィールド
タイプ
説明

mergeChunks

namespace

両方の チャンク が存在する コレクション の完全修飾 名前空間 。名前空間は<database>.<collection>の形式をとります。

bounds

配列

新しい チャンク の最小キー値と最大キー値を含む配列。

authorizationを使用して実行されている配置では、組み込みロールclusterManagerは必要な特権を提供します。

注意

Use the mergeChunks only in special circumstances. For instance, when cleaning up your sharded cluster after removing many documents.

チャンクを正常にマージするには、次の条件を満たす必要があります。

  • boundsフィールドでは、 <minkey><maxkey>はマージするチャンクの下限と上限に対応する必要があります。

  • チャンクは同じシャード上に存在する必要があります。

  • チャンクは連続している必要があります。

mergeChunks これらの条件が満たされない場合、 はエラーを返します。

On success, mergeChunks returns this document:

{
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp(1510767081, 1),
"signature" : {
"hash" : BinData(0,"okKHD0QuzcpbVQg7mP2YFw6lM04="),
"keyId" : Long("6488693018630029321")
}
},
"operationTime" : Timestamp(1510767081, 1)
}

mergeChunks returns the following error message if another metadata operation is in progress on the chunks collection:

errmsg: "The collection's metadata lock is already taken."

If another process, such as balancer process, changes metadata while mergeChunks is running, you may see this error. You can retry the mergeChunks operation without side effects.

If the input chunks are not on the same shard, mergeChunks returns an error similar to the following:

{
"ok" : 0,
"errmsg" : "could not merge chunks, collection test.users does not contain a chunk ending at { username: \"user63169\" }",
"$clusterTime" : {
"clusterTime" : Timestamp(1510767081, 1),
"signature" : {
"hash" : BinData(0,"okKHD0QuzcpbVQg7mP2YFw6lM04="),
"keyId" : Long("6488693018630029321")
}
},
"operationTime" : Timestamp(1510767081, 1)
}

If the input chunks are not contiguous, mergeChunks returns an error similar to the following:

{
"ok" : 0,
"errmsg" : "could not merge chunks, collection test.users has more than 2 chunks between [{ username: \"user29937\" }, { username: \"user49877\" })"
"$clusterTime" : {
"clusterTime" : Timestamp(1510767081, 1),
"signature" : {
"hash" : BinData(0,"okKHD0QuzcpbVQg7mP2YFw6lM04="),
"keyId" : Long("6488693018630029321")
}
},
"operationTime" : Timestamp(1510767081, 1)
}