shutdown (original) (raw)

Changed in version 5.0.

shutdown

The shutdown command cleans up all database resources and then terminates the process. You must issue the shutdown command against the admin database.

This command is available in deployments hosted in the following environments:

Important

This command is not supported in M0, M2, M5, M10+, and Flex clusters. For more information, see Unsupported Commands.

The command has the following syntax:


db.adminCommand(

   {

     shutdown: 1,

     force: <boolean>

     timeoutSecs: <int>,

     comment: <any>

   }

)

The command takes these fields:

Field Description
shutdown Specify 1.
force Optional. Specify true to force the mongodor mongos to shut down. Force shutdown interrupts any ongoing operations on the mongodor mongos and may result in unexpected behavior.You can pause and resume in-progress index builds usingforce. See shutdown on Replica Set Members for more information.
timeoutSecs Optional.Starting in MongoDB 5.0, mongod and mongosenter a quiesce period to allow any ongoing database operations to complete before shutting down.If a mongod primary receives a shut down request, the primary:Attempts to step down to a secondary.If the step down fails and a:shutdown or db.shutdownServer() command was run, mongod only continues the shut down steps if the force field is true, or aSIGTERM signal was sent to mongod,mongod always continues the shut down steps.Enters the quiesce period.Ends any remaining database operations.Shuts down.For a mongod secondary or mongosshut down request, the quiesce period is entered after a shut down was requested.The quiesce period is specified by the:timeoutSecs field if a shutdown ordb.shutdownServer() command was run, orshutdownTimeoutMillisForSignaledShutdown server parameter if a SIGTERM signal was sent to mongod, ormongosShutdownTimeoutMillisForSignaledShutdown server parameter if a SIGTERM signal was sent to mongos.Clients cannot open new connections to a mongod ormongos that is shutting down.timeoutSecs specifies a time period in seconds. The default is:15 seconds starting in MongoDB 5.0.10 seconds in MongoDB versions earlier than 5.0.mongod uses timeoutSecs as follows:If the current node is the primary node of a replica set,mongod waits for a period of up to the number of seconds specified by the timeoutSecs field for an electable node to catch up before stepping down the primary node. For details about the catch up time, see replication lag.If the current node is in the SECONDARY state after stepping down from being the primary, any remaining time specified intimeoutSecs 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.
comment Optional. A user-provided comment to attach to this command. Once set, this comment appears alongside records of this command in the following locations:mongod log messages, in theattr.command.cursor.comment field.Database profiler output, in the command.comment field.currentOp output, in the command.comment field.A comment can be any valid BSON type(string, integer, object, array, etc).

See also:

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

For a mongod started without Authentication on Self-Managed Deployments, you must run shutdown 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.

shutdown fails if the replica set member is running certain operations such as index builds. You can specifyforce: true to force the member to save index build progress to disk. The mongodrecovers the index build when it restarts and continues from the saved checkpoint.

Starting in MongoDB 5.0, mongod and mongosenter a quiesce period to allow any ongoing database operations to complete before shutting down.

If a mongod primary receives a shut down request, the primary:

  1. Attempts to step down to a secondary.
    If the step down fails and a:
  2. Enters the quiesce period.
  3. Ends any remaining database operations.
  4. Shuts down.

For a mongod secondary or mongosshut down request, the quiesce period is entered after a shut down was requested.

The quiesce period is specified by the:

Clients cannot open new connections to a mongod ormongos that is shutting down.

timeoutSecs specifies a time period in seconds. The default is:

mongod uses timeoutSecs as follows:

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.

Warning

Force shutdown of the primary can result in therollback of any writes not yet replicated to a secondary.

To run shutdown on a mongod enforcingAuthentication on Self-Managed Deployments, the authenticated user must have theshutdown privilege. For example, a user with the built-in role hostManager has the appropriate permissions.


db.adminCommand({ "shutdown" : 1 })


db.adminCommand({ "shutdown" : 1, "force" : true })


db.adminCommand({ "shutdown" : 1, timeoutSecs: 60 })