- Reference >
- Database Commands >
- Administration Commands >
- shutdown
shutdown¶
On this page
Changed in version 5.0.
-
shutdown¶ The
shutdowncommand cleans up all database resources and then terminates the process. You must issue theshutdowncommand against the admin database.The command has this syntax:
The command takes these fields:
Field Description shutdown Specify
1.force Optional. Specify
trueto force themongodormongosto shut down. Force shutdown interrupts any ongoing operations on themongodormongosand may result in unexpected behavior.timeoutSecs Optional.
Starting in MongoDB 5.0,
mongodandmongosenter a quiesce period to allow any ongoing database operations to complete before shutting down.If a
mongodprimary receives a shut down request, the primary:Attempts to step down to a secondary.
If the step down fails and a:
shutdownordb.shutdownServer()command was run,mongodonly continues the shut down steps if the force field is true, or aSIGTERMsignal was sent tomongod,mongodalways continues the shut down steps.
Enters the quiesce period.
Ends any remaining database operations.
Shuts down.
For a
mongodsecondary ormongosshut down request, the quiesce period is entered after a shut down was requested.The quiesce period is specified by the:
- timeoutSecs field if a
shutdownordb.shutdownServer()command was run, or shutdownTimeoutMillisForSignaledShutdownserver parameter if aSIGTERMsignal was sent tomongod, ormongosShutdownTimeoutMillisForSignaledShutdownserver parameter if aSIGTERMsignal was sent tomongos.
The timeoutSecs field defaults to
15seconds in MongoDB 5.0.Clients cannot open new connections to a
mongodormongosthat is shutting down.In MongoDB 4.4 and earlier, for a
mongodprimary, timeoutSecs is the number of seconds the primary should wait for a secondary to catch up. If no secondaries catch up within the specified time, the command fails. Defaults to10seconds.commentOptional. 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 the
attr.command.cursor.commentfield. - Database profiler output, in the
command.commentfield. currentOpoutput, in thecommand.commentfield.
A comment can be any valid BSON type (string, integer, object, array, etc).
New in version 4.4.
See also
Behavior¶
For a mongod started with Authentication,
you must run shutdown over an authenticated connection.
See Access Control for more information.
For a mongod started without Authentication,
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 on Replica Set Members¶
shutdown fails if the replica set member is running
certain operations such as index builds. You can specify
force: true to force the member
to interrupt those operations and shut down.
Shutting Down the Replica Set Primary, Secondary, or mongos¶
Starting in MongoDB 5.0, mongod and mongos
enter 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:
shutdownordb.shutdownServer()command was run,mongodonly continues the shut down steps if the force field is true, or aSIGTERMsignal was sent tomongod,mongodalways continues the shut down steps.
Enters the quiesce period.
Ends any remaining database operations.
Shuts down.
For a mongod secondary or mongos
shut down request, the quiesce period is entered after a shut down was
requested.
The quiesce period is specified by the:
- timeoutSecs field if a
shutdownordb.shutdownServer()command was run, or shutdownTimeoutMillisForSignaledShutdownserver parameter if aSIGTERMsignal was sent tomongod, ormongosShutdownTimeoutMillisForSignaledShutdownserver parameter if aSIGTERMsignal was sent tomongos.
The timeoutSecs field defaults to 15 seconds in MongoDB 5.0.
Clients cannot open new connections to a mongod or
mongos that is shutting down.
In MongoDB 4.4 and earlier, if running shutdown against the
replica set primary, the operation implicitly uses
replSetStepDown to step down the primary before shutting
down the mongod. If no secondary in the replica set can
catch up to the primary within 10 seconds, the shutdown operation
fails. You can issue shutdown with force: true to shut down the primary even if the step down
fails.
Warning
Force shutdown of the primary can result in the rollback of any writes not yet replicated to a secondary.
Access Control¶
To run shutdown on a mongod enforcing
Authentication, the authenticated user must have the
shutdown privilege. For example, a user with the
built-in role hostManager has the appropriate permissions.