|
MongoDB is run as a standard program from the command line. Please see Command Line Parameters for more information on those options. The following examples assume that you are in the directory where the Mongo executable is, and the Mongo executable is called mongod. Starting MongoDefault Data Directory, Default PortTo start Mongo in default mode, where data will be stored in the /data/db directory (or c:\data\db on Windows), and listening on port 27017, just type $ ./mongod Alternate Data Directory, Default PortTo specify a directory for Mongo to store files, use the --dbpath option: $ ./mongod --dbpath /var/lib/mongodb/
Note that you must create the directory and set its permissions appropriately ahead of time -- Mongo will not create the directory if it doesn't exist. Alternate PortYou can specify a different port for Mongo to listen on for connections from clients using the --port option $ ./mongod --port 12345 This is useful if you want to run more than one instance of Mongo on a machine (e.g., for running a master-slave pair). Running as a DaemonNote: these options are only available in MongoDB version 1.1 and later. This will fork the Mongo server and redirect its output to a logfile. As with --dbpath, you must create the log path yourself, Mongo will not create parent directories for you. $ ./mongod --fork --logpath /var/log/mongodb.log --logappend
Stopping MongoControl-CIf you have Mongo running in the foreground in a terminal, you can simply "Ctrl-C" the process. This will cause Mongo to do a clean exit, flushing and closing it's data files. Note that it will wait until all ongoing operations are complete. Sending shutdownServer() message from the mongo shellThe shell can request that the server terminate. $ ./mongo > db.shutdownServer() This command only works from localhost, or, if one is authenticated. From a driver (where the helper function may not exist), one can run the command { "shutdown" : 1 }
Sending a Unix INT or TERM signalYou can cleanly stop mongod using a SIGINT or SIGTERM signal on Unix-like systems. Either ^C, "kill -2 PID," or kill -15 PID will work.
Memory UsageMongo uses memory mapped files to access data, which results in large numbers being displayed in tools like top for the mongod process. This is not a concern, and is normal when using memory-mapped files. Basically, the size of mapped data is shown in the virtual size parameter, and resident bytes shows how much data is being cached in RAM. You can get a feel for the "inherent" memory footprint of Mongo by starting it fresh, with no connections, with an empty /data/db directory and looking at the resident bytes. |

PLEASE POST QUESTIONS IN THE USER GROUPS FORUM. Post non-question comments and helpful hints here.
blog comments powered by Disqus