バージョン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 specifies a time period in seconds. The default is:
MongoDB 5.0 以降のバージョンでは 15 秒です。
MongoDB 5.0 以前のバージョンでは 10 秒です。
mongoduses timeoutSecs as follows:現在のノードがレプリカセットのプライマリノードである場合、
mongodはプライマリ ノードを降格する前に、選択可能なノードが追いつくまでtimeoutSecsフィールドで指定された秒数まで待機します。 キャッチアップ時間の詳細については、「レプリケーションラグ 」を参照してください。If the current node is in the
SECONDARYstate after stepping down from being the primary, any remaining time specified in timeoutSecs is used for a quiesce period, which allows existing operations to complete. New operations are sent to other replica set nodes.
Starting in MongoDB 5.0,
mongosuses timeoutSecs as a quiesce period, which allows existing operations to complete. New operations are sent to othermongosnodes. In MongoDB versions earlier than 5.0,mongosshuts down immediately and does not use timeoutSecs.
この操作はshutdownコマンドのラッパーを提供します。
互換性
このメソッドは、次の環境でホストされている配置で使用できます。
重要
This command is not supported in MongoDB Atlas clusters. For information on Atlas support for all commands, see Unsupported Commands.
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 specifies a time period in seconds. The default is:
MongoDB 5.0 以降のバージョンでは 15 秒です。
MongoDB 5.0 以前のバージョンでは 10 秒です。
mongod uses timeoutSecs as follows:
現在のノードがレプリカセットのプライマリノードである場合、
mongodはプライマリ ノードを降格する前に、選択可能なノードが追いつくまでtimeoutSecsフィールドで指定された秒数まで待機します。 キャッチアップ時間の詳細については、「レプリケーションラグ 」を参照してください。If the current node is in the
SECONDARYstate after stepping down from being the primary, any remaining time specified in timeoutSecs is used for a quiesce period, which allows existing operations to complete. New operations are sent to other replica set nodes.
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 })