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

db.shutdownServer()(mongoshメソッド)

バージョン5.0で変更。

db.shutdownServer()

Shuts down the current mongod or mongos process cleanly and safely. You must issue the db.shutdownServer() operation against the admin database.

db.shutdownServer() の構文は次のとおりです。

db.shutdownServer({
force: <boolean>,
timeoutSecs: <int>
})

メソッドは次のフィールドを取ります。

フィールド
説明

任意: mongod または mongos を強制的にシャットダウンするには、true を指定します。強制シャットダウンは、mongod または mongos で実行中の操作を中断し、予期しない動作が発生する可能性があります。

You can pause and resume in-progress index builds using force. See db.shutdownServer() on Replica Set Members for more information.

任意。

MongoDB 5.0 以降では、mongodmongos は、シャットダウン前に進行中のデータベース操作を完了できるように休止期間に入ります。

mongod プライマリがシャットダウン要求を受信すると、プライマリは次の処理を実行します。

  1. セカンダリへのステップダウンを試みます。

    ステップダウンに失敗し…

  2. 休止期間に入ります。

  3. 残りのデータベース操作を終了します。

  4. シャットダウンします。

mongod セカンダリまたは mongos シャットダウン要求の場合、シャットダウンが要求された後に休止期間に入ります。

休止期間は、次の方法で指定されます。

クライアントは、シャットダウン中の mongod または mongos への新しい接続を開くことができません。

timeoutSecsは、秒単位で期間を指定します。 デフォルトは次のとおりです。

  • MongoDB 5.0 以降のバージョンでは 15 秒です。

  • MongoDB 5.0 以前のバージョンでは 10 秒です。

mongodtimeoutSecsを次のように使用します。

  • 現在のノードがレプリカセットのプライマリノードである場合、 mongodはプライマリ ノードを降格する前に、選択可能なノードが追いつくまでtimeoutSecsフィールドで指定された秒数まで待機します。 キャッチアップ時間の詳細については、「レプリケーションラグ 」を参照してください。

  • プライマリから降格した後に現在のノードがSECONDARY状態になっている場合、 timeoutSecsで指定された残りの時間は休止期間に使用され、既存の操作を完了できます。 新しい操作は他のレプリカセット ノードに送信されます。

MongoDB5.0 以降、mongos timeoutSecs を休止期間として使用し、既存の操作を完了できるようにします。新しい操作は他のmongos ノードに送信されます。. より前のバージョンのMongoDBでは、 はすぐにシャットダウンし、5 0mongostimeoutSecs を使用しません。

この操作はshutdownコマンドのラッパーを提供します。

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

重要

このコマンドは、MongoDB Atlas クラスターではサポートされていません。すべてのコマンドに対する Atlas のサポートについては、「サポートされていないコマンド」を参照してください。

  • MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン

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

For a mongod started with Authentication on Self-Managed Deployments, you must run db.shutdownServer() over an authenticated connection. See Access Control for more information.

For a mongod started without Authentication on Self-Managed Deployments, you must run db.shutdownServer() from a client connected to the localhost interface. For example, run mongosh with the --host "127.0.0.1" option on the same host machine as the mongod.

db.shutdownServer() fails if the mongod replica set member is running certain operations such as index builds. You can specify force: true to save index build progress to disk. The mongod recovers the index build when it restarts and continues from the saved checkpoint.

MongoDB 5.0 以降では、mongodmongos は、シャットダウン前に進行中のデータベース操作を完了できるように休止期間に入ります。

mongod プライマリがシャットダウン要求を受信すると、プライマリは次の処理を実行します。

  1. セカンダリへのステップダウンを試みます。

    ステップダウンに失敗し…

  2. 休止期間に入ります。

  3. 残りのデータベース操作を終了します。

  4. シャットダウンします。

mongod セカンダリまたは mongos シャットダウン要求の場合、シャットダウンが要求された後に休止期間に入ります。

休止期間は、次の方法で指定されます。

クライアントは、シャットダウン中の mongod または mongos への新しい接続を開くことができません。

timeoutSecsは、秒単位で期間を指定します。 デフォルトは次のとおりです。

  • MongoDB 5.0 以降のバージョンでは 15 秒です。

  • MongoDB 5.0 以前のバージョンでは 10 秒です。

mongodtimeoutSecsを次のように使用します。

  • 現在のノードがレプリカセットのプライマリノードである場合、 mongodはプライマリ ノードを降格する前に、選択可能なノードが追いつくまでtimeoutSecsフィールドで指定された秒数まで待機します。 キャッチアップ時間の詳細については、「レプリケーションラグ 」を参照してください。

  • プライマリから降格した後に現在のノードがSECONDARY状態になっている場合、 timeoutSecsで指定された残りの時間は休止期間に使用され、既存の操作を完了できます。 新しい操作は他のレプリカセット ノードに送信されます。

Starting in MongoDB 5.0, mongos uses timeoutSecs as a quiesce period, which allows existing operations to complete. New operations are sent to other mongos nodes. In MongoDB versions earlier than 5.0, mongos shuts down immediately and does not use timeoutSecs.

警告

プライマリを強制的にシャットダウンすると、セカンダリにまだレプリケートされていない書込みが ロールバックされる可能性があります。

To run db.shutdownServer() on a mongod enforcing Authentication on Self-Managed Deployments, the authenticated user must have the db.shutdownServer() privilege. For example, a user with the built-in role hostManager has the appropriate permissions.

db.getSiblingDB("admin").shutdownServer()
db.getSiblingDB("admin").shutdownServer({ "force" : true })
db.getSiblingDB("admin").shutdownServer({ "timeoutSecs": 60 })
このページを評価