バージョン5.0で変更。
db.shutdownServer()Shuts down the current
mongodormongosprocess cleanly and safely. You must issue thedb.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. Seedb.shutdownServer()on Replica Set Members for more information.任意。
MongoDB 5.0 以降では、
mongodとmongosは、シャットダウン前に進行中のデータベース操作を完了できるように休止期間に入ります。mongodプライマリがシャットダウン要求を受信すると、プライマリは次の処理を実行します。休止期間に入ります。
残りのデータベース操作を終了します。
シャットダウンします。
mongodセカンダリまたはmongosシャットダウン要求の場合、シャットダウンが要求された後に休止期間に入ります。休止期間は、次の方法で指定されます。
timeoutSecs field if a
shutdownordb.shutdownServer()command was run, orSIGTERMシグナルがmongodに送信された場合は、shutdownTimeoutMillisForSignaledShutdownサーバー パラメーター、またはSIGTERMシグナルがmongosに送信された場合は、mongosShutdownTimeoutMillisForSignaledShutdownになります。
クライアントは、シャットダウン中の
mongodまたはmongosへの新しい接続を開くことができません。timeoutSecsは、秒単位で期間を指定します。 デフォルトは次のとおりです。
MongoDB 5.0 以降のバージョンでは 15 秒です。
MongoDB 5.0 以前のバージョンでは 10 秒です。
mongodはtimeoutSecsを次のように使用します。現在のノードがレプリカセットのプライマリノードである場合、
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() レプリカセット ノード
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.
レプリカ・セットのシャットダウン プライマリ、セカンダリ、または mongos
MongoDB 5.0 以降では、mongod と mongos は、シャットダウン前に進行中のデータベース操作を完了できるように休止期間に入ります。
mongod プライマリがシャットダウン要求を受信すると、プライマリは次の処理を実行します。
休止期間に入ります。
残りのデータベース操作を終了します。
シャットダウンします。
mongod セカンダリまたは mongos シャットダウン要求の場合、シャットダウンが要求された後に休止期間に入ります。
休止期間は、次の方法で指定されます。
timeoutSecs field if a
shutdownordb.shutdownServer()command was run, orSIGTERMシグナルがmongodに送信された場合は、shutdownTimeoutMillisForSignaledShutdownサーバー パラメーター、またはSIGTERMシグナルがmongosに送信された場合は、mongosShutdownTimeoutMillisForSignaledShutdownになります。
クライアントは、シャットダウン中の mongod または mongos への新しい接続を開くことができません。
timeoutSecsは、秒単位で期間を指定します。 デフォルトは次のとおりです。
MongoDB 5.0 以降のバージョンでは 15 秒です。
MongoDB 5.0 以前のバージョンでは 10 秒です。
mongodはtimeoutSecsを次のように使用します。
現在のノードがレプリカセットのプライマリノードである場合、
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.
例
次をシャットダウンします: mongod
db.getSiblingDB("admin").shutdownServer()
強制シャットダウン mongod
db.getSiblingDB("admin").shutdownServer({ "force" : true })
より長いタイムアウトでプライマリ mongod をシャットダウンする
db.getSiblingDB("admin").shutdownServer({ "timeoutSecs": 60 })