Databases Reference
In-Depth Information
logpath = mongodb.log
This configuration file specifies the same options we used earlier when starting with
regular command-line arguments. It also highlights most of the interesting aspects of
MongoDB configuration files:
• Any text on a line that follows the # character is ignored as a comment.
• The syntax for specifying options is
option
=
value
, where
option
is case-sensitive.
• For command-line switches like
--fork
, the value
true
should be used.
Stopping MongoDB
Being able to safely stop a running MongoDB server is at least as important as being
able to start one. There are a couple of different options for doing this effectively.
The most basic way to stop a running MongoDB server is to send it a SIGINT or
SIGTERM signal. If the server is running as the foreground process in a terminal, this
can be done by pressing Ctrl-C. Otherwise, a command like
kill
can be used to send
the signal. If
mongod
has 10014 as its PID, the command would be
kill -2 10014
(SIGINT) or
kill 10014
(SIGTERM).
When
mongod
receives a SIGINT or SIGTERM, it will do a clean shutdown. This means
it will wait for any currently running operations or file preallocations to finish (this
could take a moment), close all open connections, flush all data to disk, and halt.
It is important not to send a SIGKILL message (
kill -9
) to a running
MongoDB server. Doing so will cause the database to shut down with-
out going through the steps outlined earlier and could lead to corrupt
data files. If this happens, the database should be repaired (see
“Re-
pair” on page 124
) before being started back up.
Another way to cleanly shut down a running server is to use the
shutdown
command,
{"shutdown" : 1}
. This is an admin command and must be run on the
admin
database.
The shell features a helper function to make this easier:
> use admin
switched to db admin
> db.shutdownServer();
server should be down...
Monitoring
As the administrator of a MongoDB server, it's important to monitor the health and
performance of your system. Fortunately, MongoDB has functionality that makes
monitoring easy.