Starting and stopping mongodb server

By using the “mongod” command we can start the database and configure the database using the same. Below are basic options to configure the mongo db.

Common configuration options :-

–port : port number (by default 27017).
–bind_ip : list of comma separated ip address on which the listener will listen.
–logpath : log file to send write to instead of stdout.
                 db.adminCommand({“setParameter” : 1, “logLevel” : 3}) èthis will set the loglevel (we can set upto 5) for more info about the mongod operations and debugging.
                 db.setProfilingLevel(1, 500) à log the queries taking more time than 500ms.
–logrotate : set the log rotation behavior
     Rename:Rename the existing logfile with timestamp and open a new logfile.
     Reopen : Open the new logfile with same name. (This expect a new process will rename the logfile ,       before it reopen)
–config : use the configuration file for additional options not mentioned in the command line.

Specifically for windows :-

–install : create a service
–remove : remove service
–reinstall : reinstall the service
–serviceName : name of the service
–serviceDisplayName : service display name
–serviceUser : account for service execution

–storageEngine :What is the storage engine need to be used. (by default weired tiger)
–dbpath :directory for datafiles (when we start the mongo instance , it will create a lock file in this location , represent an instance is running on this directory).
–directoryperdb :Each db will be stored in separate directory.
–noprealloc :disable data file preallocation – this will hamper the performance.
–quota : limit the size of database by specifying the number of files.
–nssize : .ns files size in MB
–upgrade :upgrade database
–journal :enable journaling
–nojournal :disable journaling
Configuring mongodb service.

C:\Program Files\MongoDB\Server\3.2\bin\mongod.exe –dbpath C:\MYTEST\DB –port 12345 –bind_ip –logpath C:\MONGOLOGS\back.log –logRotate rename –directoryperdb –install –serviceName “mymongodb”
This will create a service named “mymongodb”

net start mymongodb èStart the service , internally start the database instance. For the first time this will create all the database files and logfiles in the respective folders.
Starting the database for the first time take more as time as it need to create the database files.
Stopping mongodb server :-

db.shudownServer() – This command will stop the database server.
If we want to stop the server forcefully then we can use the force option.
We can also use the linux kill command to kill the server process.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s