Start and stop script for MongoDB servers

MongoDB
Tags:

For the good or for the bad, you can learn to work with MongoDB on your own PC or laptop without installing anything, just by having located the path where MongoDB server is, a config file and a path where data is stored.

On previous post I have explained about how to config a MongoDB server, how to start up a server, … I think it’s good to create a small  .bat script to speed up everything, and reducing the possibility of generating errors. So, just go to a text editor and write:

@echo Off
echo —————————————–
echo . Starting the MongoDB instance
echo —————————————–
start mongod.exe –config c:\mongodb\mongo.conf
start mongo.exe
exit

Now, you can save it as start.bat  in the same path bin of MongoDB, and this way, just with one clic, you can start up the server and a MongoDB console. As a remainder, watch out for the path of your confi file.

To end with, I would like to comment that if you need tos stop a MongoDB server, on the official documentation for Windows you can use CTRL+C on the mongod server console, and it’s anought. However, sometimes, after using this method, you can have some problems to start it again. (al least, I suffer some problems, and that’s why I create this scripts).

In order to solve this issues, just create another file called stop.bat , that we save on the same bon dir ofmongoDB with the text:

@echo Off
echo —————————————–
echo . Starting the MongoDB instance
echo —————————————–
mongo –eval “db.getSiblingDB(‘admin’).shutdownServer()”

And when you need to stop the server, just use stop.bat, and you will avoid a lot of problems!

As we see in another previous post, it’s important to know where the mongoDB log file is, in case you have some problem, because it can help you to solve them!

I hope you like it and use this script! Have a nice day!